mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-02-19 12:04:54 +00:00
Store group id and file id instead of full keys.
This commit is contained in:
parent
62727d6831
commit
bd06158d4c
4 changed files with 17 additions and 17 deletions
|
@ -158,7 +158,8 @@ namespace dindb {
|
|||
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()));
|
||||
|
||||
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());
|
||||
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;
|
||||
|
@ -192,13 +193,13 @@ namespace dindb {
|
|||
"is_symlink", (file_data.is_symlink ? '1' : '0'),
|
||||
"unreadable", (file_data.unreadable ? '1' : '0'),
|
||||
"hash_valid", (file_data.hash_valid ? '1' : '0'),
|
||||
"group_id", set_key
|
||||
"group_id", group_id
|
||||
);
|
||||
|
||||
batch.run(
|
||||
"SADD",
|
||||
PROGRAM_NAME ":hash:" + hash,
|
||||
file_key
|
||||
lexical_cast<std::string>(z)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
local tag_key = KEYS[1]
|
||||
local file_key = KEYS[2]
|
||||
local group_key = ARGV[1]
|
||||
local group_id = ARGV[1]
|
||||
|
||||
local function split_string(inputstr, sep)
|
||||
if sep == nil then
|
||||
|
@ -45,9 +45,9 @@ local function dele_tag_from_list(tag_list, dele_tag)
|
|||
return table.concat(tag_list, ",")
|
||||
end
|
||||
|
||||
if group_key ~= "" then
|
||||
local found_group_key = redis.call("HGET", file_key, "group_id")
|
||||
if found_group_key ~= group_key then
|
||||
if group_id ~= 0 then
|
||||
local found_group_id = redis.call("HGET", file_key, "group_id")
|
||||
if found_group_id ~= group_id then
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
|
|
@ -58,14 +58,14 @@ namespace dindb {
|
|||
using dinhelp::lexical_cast;
|
||||
|
||||
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 &tag : parTags) {
|
||||
std::ostringstream oss;
|
||||
oss << PROGRAM_NAME ":tag:" << tag;
|
||||
const std::string tag_key = oss.str();
|
||||
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) {
|
||||
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);
|
||||
for (const auto &itm : parRedis.scan(PROGRAM_NAME ":file:*")) {
|
||||
const auto &file_key = itm;
|
||||
|
@ -90,7 +90,7 @@ namespace dindb {
|
|||
std::ostringstream oss;
|
||||
oss << PROGRAM_NAME ":tag:" << tag;
|
||||
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;
|
||||
}
|
||||
|
@ -144,7 +144,6 @@ namespace dindb {
|
|||
void delete_all_tags (redis::Command& parRedis, redis::Script& parDeleIfInSet, const std::vector<std::string>& parRegexes, GroupIDType parSet) {
|
||||
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);
|
||||
|
||||
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_replies = redis::get_array(file_reply);
|
||||
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)
|
||||
continue;
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
local tag_key = KEYS[1]
|
||||
local file_key = KEYS[2]
|
||||
local group_key = ARGV[1]
|
||||
local group_id = ARGV[1]
|
||||
|
||||
local function split_string(inputstr, sep)
|
||||
if sep == nil then
|
||||
|
@ -51,9 +51,9 @@ local function add_tag_to_list(tag_list, new_tag)
|
|||
return table.concat(tag_list, ",")
|
||||
end
|
||||
|
||||
if group_key ~= "" then
|
||||
local found_group_key = redis.call("HGET", file_key, "group_id")
|
||||
if found_group_key ~= group_key then
|
||||
if group_id ~= 0 then
|
||||
local found_group_id = redis.call("HGET", file_key, "group_id")
|
||||
if found_group_id ~= group_id then
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue