1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2025-02-20 12:14:55 +00:00

Store group id and file id instead of full keys.

This commit is contained in:
King_DuckZ 2016-07-11 17:44:54 +01:00
parent 62727d6831
commit bd06158d4c
4 changed files with 17 additions and 17 deletions

View file

@ -158,7 +158,8 @@ namespace dindb {
redis::Reply set_id_reply = m_redis.run("HINCRBY", PROGRAM_NAME ":indices", "set", "1"); redis::Reply set_id_reply = m_redis.run("HINCRBY", PROGRAM_NAME ":indices", "set", "1");
redis::Reply file_id_reply = m_redis.run("HINCRBY", PROGRAM_NAME ":indices", "files", lexical_cast<std::string>(parData.size())); redis::Reply file_id_reply = m_redis.run("HINCRBY", PROGRAM_NAME ":indices", "files", lexical_cast<std::string>(parData.size()));
const std::string set_key = PROGRAM_NAME ":set:" + lexical_cast<std::string>(redis::get_integer(set_id_reply)); const auto group_id = lexical_cast<std::string>(redis::get_integer(set_id_reply));
const std::string set_key = PROGRAM_NAME ":set:" + group_id;
const auto casted_data_size = static_cast<decltype(redis::get_integer(file_id_reply))>(parData.size()); const auto casted_data_size = static_cast<decltype(redis::get_integer(file_id_reply))>(parData.size());
assert(redis::get_integer(file_id_reply) >= casted_data_size); assert(redis::get_integer(file_id_reply) >= casted_data_size);
const auto base_file_id = redis::get_integer(file_id_reply) - casted_data_size + 1; const auto base_file_id = redis::get_integer(file_id_reply) - casted_data_size + 1;
@ -192,13 +193,13 @@ namespace dindb {
"is_symlink", (file_data.is_symlink ? '1' : '0'), "is_symlink", (file_data.is_symlink ? '1' : '0'),
"unreadable", (file_data.unreadable ? '1' : '0'), "unreadable", (file_data.unreadable ? '1' : '0'),
"hash_valid", (file_data.hash_valid ? '1' : '0'), "hash_valid", (file_data.hash_valid ? '1' : '0'),
"group_id", set_key "group_id", group_id
); );
batch.run( batch.run(
"SADD", "SADD",
PROGRAM_NAME ":hash:" + hash, PROGRAM_NAME ":hash:" + hash,
file_key lexical_cast<std::string>(z)
); );
} }

View file

@ -16,7 +16,7 @@
local tag_key = KEYS[1] local tag_key = KEYS[1]
local file_key = KEYS[2] local file_key = KEYS[2]
local group_key = ARGV[1] local group_id = ARGV[1]
local function split_string(inputstr, sep) local function split_string(inputstr, sep)
if sep == nil then if sep == nil then
@ -45,9 +45,9 @@ local function dele_tag_from_list(tag_list, dele_tag)
return table.concat(tag_list, ",") return table.concat(tag_list, ",")
end end
if group_key ~= "" then if group_id ~= 0 then
local found_group_key = redis.call("HGET", file_key, "group_id") local found_group_id = redis.call("HGET", file_key, "group_id")
if found_group_key ~= group_key then if found_group_id ~= group_id then
return nil return nil
end end
end end

View file

@ -58,14 +58,14 @@ namespace dindb {
using dinhelp::lexical_cast; using dinhelp::lexical_cast;
auto batch = parRedis.make_batch(); auto batch = parRedis.make_batch();
const std::string set_key = (parSet != InvalidGroupID ? PROGRAM_NAME ":set:" + lexical_cast<std::string>(parSet) : ""); const std::string set_id = lexical_cast<std::string>(parSet);
for (const auto file_id : parFiles) { for (const auto file_id : parFiles) {
for (const auto &tag : parTags) { for (const auto &tag : parTags) {
std::ostringstream oss; std::ostringstream oss;
oss << PROGRAM_NAME ":tag:" << tag; oss << PROGRAM_NAME ":tag:" << tag;
const std::string tag_key = oss.str(); const std::string tag_key = oss.str();
const std::string file_key = make_file_key(file_id); const std::string file_key = make_file_key(file_id);
parScript.run(batch, std::make_tuple(tag_key, file_key), std::make_tuple(set_key)); parScript.run(batch, std::make_tuple(tag_key, file_key), std::make_tuple(set_id));
} }
} }
@ -75,7 +75,7 @@ namespace dindb {
void run_regex_based_script(redis::Command& parRedis, redis::Script& parTagIfInSet, const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, GroupIDType parSet) { void run_regex_based_script(redis::Command& parRedis, redis::Script& parTagIfInSet, const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, GroupIDType parSet) {
using dinhelp::lexical_cast; using dinhelp::lexical_cast;
const std::string set_key = (parSet != InvalidGroupID ? PROGRAM_NAME ":set:" + lexical_cast<std::string>(parSet) : ""); const std::string set_id = lexical_cast<std::string>(parSet);
const auto regexes = compile_regexes(parRegexes); const auto regexes = compile_regexes(parRegexes);
for (const auto &itm : parRedis.scan(PROGRAM_NAME ":file:*")) { for (const auto &itm : parRedis.scan(PROGRAM_NAME ":file:*")) {
const auto &file_key = itm; const auto &file_key = itm;
@ -90,7 +90,7 @@ namespace dindb {
std::ostringstream oss; std::ostringstream oss;
oss << PROGRAM_NAME ":tag:" << tag; oss << PROGRAM_NAME ":tag:" << tag;
const std::string tag_key = oss.str(); const std::string tag_key = oss.str();
parTagIfInSet.run(batch, std::make_tuple(tag_key, file_key), std::make_tuple(set_key)); parTagIfInSet.run(batch, std::make_tuple(tag_key, file_key), std::make_tuple(set_id));
} }
break; break;
} }
@ -144,7 +144,6 @@ namespace dindb {
void delete_all_tags (redis::Command& parRedis, redis::Script& parDeleIfInSet, const std::vector<std::string>& parRegexes, GroupIDType parSet) { void delete_all_tags (redis::Command& parRedis, redis::Script& parDeleIfInSet, const std::vector<std::string>& parRegexes, GroupIDType parSet) {
using dinhelp::lexical_cast; using dinhelp::lexical_cast;
const std::string set_key = (parSet != InvalidGroupID ? PROGRAM_NAME ":set:" + lexical_cast<std::string>(parSet) : "");
const auto regexes = compile_regexes(parRegexes); const auto regexes = compile_regexes(parRegexes);
std::set<std::string> dele_tags; std::set<std::string> dele_tags;
@ -155,7 +154,7 @@ namespace dindb {
auto file_reply = parRedis.run("HMGET", file_key, "path", "tags", "group_id"); auto file_reply = parRedis.run("HMGET", file_key, "path", "tags", "group_id");
auto& file_replies = redis::get_array(file_reply); auto& file_replies = redis::get_array(file_reply);
assert(file_replies.size() == 3); assert(file_replies.size() == 3);
const auto group_id = id_from_redis_key<GroupIDType>(redis::get_string(file_replies[2])); const auto group_id = lexical_cast<GroupIDType>(redis::get_string(file_replies[2]));
if (parSet != InvalidGroupID and parSet != group_id) if (parSet != InvalidGroupID and parSet != group_id)
continue; continue;

View file

@ -16,7 +16,7 @@
local tag_key = KEYS[1] local tag_key = KEYS[1]
local file_key = KEYS[2] local file_key = KEYS[2]
local group_key = ARGV[1] local group_id = ARGV[1]
local function split_string(inputstr, sep) local function split_string(inputstr, sep)
if sep == nil then if sep == nil then
@ -51,9 +51,9 @@ local function add_tag_to_list(tag_list, new_tag)
return table.concat(tag_list, ",") return table.concat(tag_list, ",")
end end
if group_key ~= "" then if group_id ~= 0 then
local found_group_key = redis.call("HGET", file_key, "group_id") local found_group_id = redis.call("HGET", file_key, "group_id")
if found_group_key ~= group_key then if found_group_id ~= group_id then
return nil return nil
end end
end end