mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-07-03 14:14:11 +00:00
Implement delete all tags by id.
This commit is contained in:
parent
f12d498e40
commit
83fe7c75d6
2 changed files with 35 additions and 2 deletions
|
@ -63,6 +63,6 @@ end
|
|||
|
||||
local retval = redis.call("SREM", tag_key, file_key)
|
||||
if redis.call("SCARD", tag_key) == 0 then
|
||||
redis.call("SREM", tag_key)
|
||||
redis.call("DEL", tag_key)
|
||||
end
|
||||
return retval
|
||||
|
|
|
@ -19,12 +19,28 @@
|
|||
#include "command.hpp"
|
||||
#include "dindexerConfig.h"
|
||||
#include "helpers/lexical_cast.hpp"
|
||||
#include "dindexer-core/split_tags.hpp"
|
||||
#include <sstream>
|
||||
#include <tuple>
|
||||
#include <regex>
|
||||
#include <unordered_set>
|
||||
#include <boost/functional/hash.hpp>
|
||||
|
||||
namespace std {
|
||||
template<>
|
||||
struct hash<boost::string_ref> {
|
||||
size_t operator() (boost::string_ref const& sr) const {
|
||||
return boost::hash_range(sr.begin(), sr.end());
|
||||
}
|
||||
};
|
||||
} //namespace std
|
||||
|
||||
namespace dindb {
|
||||
namespace {
|
||||
std::string make_file_key (uint64_t parID) {
|
||||
return PROGRAM_NAME ":file:" + dinhelp::lexical_cast<std::string>(parID);
|
||||
}
|
||||
|
||||
std::vector<std::regex> compile_regexes (const std::vector<std::string>& parRegexes) {
|
||||
std::vector<std::regex> retval;
|
||||
retval.reserve(parRegexes.size());
|
||||
|
@ -48,7 +64,7 @@ namespace dindb {
|
|||
std::ostringstream oss;
|
||||
oss << PROGRAM_NAME ":tag:" << tag;
|
||||
const std::string tag_key = oss.str();
|
||||
const std::string file_key = PROGRAM_NAME ":file:" + lexical_cast<std::string>(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));
|
||||
}
|
||||
}
|
||||
|
@ -99,6 +115,23 @@ namespace dindb {
|
|||
}
|
||||
|
||||
void delete_all_tags (redis::Command& parRedis, redis::Script& parDeleIfInSet, const std::vector<uint64_t>& parFiles, GroupIDType parSet) {
|
||||
auto batch = parRedis.make_batch();
|
||||
for (const auto file_id : parFiles) {
|
||||
const auto file_key = make_file_key(file_id);
|
||||
batch.run("HGET", file_key, "tags");
|
||||
}
|
||||
|
||||
batch.throw_if_failed();
|
||||
std::unordered_set<boost::string_ref> dele_tags;
|
||||
for (const auto& reply : batch.replies()) {
|
||||
auto tags = dincore::split_tags(redis::get_string(reply));
|
||||
for (const auto& tag : tags) {
|
||||
dele_tags.insert(tag);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<boost::string_ref> vec_dele_tags(dele_tags.begin(), dele_tags.end());
|
||||
delete_tags(parRedis, parDeleIfInSet, parFiles, vec_dele_tags, parSet);
|
||||
}
|
||||
|
||||
void delete_all_tags (redis::Command& parRedis, redis::Script& parDeleIfInSet, const std::vector<std::string>& parRegexes, GroupIDType parSet) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue