mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-02-19 12:04:54 +00:00
Implement find_file_details().
This commit is contained in:
parent
9a84f63e54
commit
f58d7d84eb
4 changed files with 37 additions and 3 deletions
|
@ -167,6 +167,7 @@ namespace dindb {
|
|||
|
||||
const auto group_id = lexical_cast<std::string>(group_id_int);
|
||||
const std::string set_key = PROGRAM_NAME ":set:" + group_id;
|
||||
const std::string level_key = PROGRAM_NAME ":levels:" + group_id;
|
||||
assert(file_id_int >= data_size);
|
||||
const auto base_file_id = file_id_int - data_size + 1;
|
||||
|
||||
|
@ -215,6 +216,8 @@ namespace dindb {
|
|||
PROGRAM_NAME ":hash:" + hash,
|
||||
lexical_cast<std::string>(z)
|
||||
);
|
||||
|
||||
batch.zadd(level_key, redis::IncRedisBatch::ZADD_None, false, static_cast<double>(file_data.level), file_key);
|
||||
#if !defined(NDEBUG)
|
||||
++inserted_count;
|
||||
#endif
|
||||
|
@ -275,7 +278,7 @@ namespace dindb {
|
|||
}
|
||||
|
||||
std::vector<dinhelp::MaxSizedArray<std::string, 1>> BackendRedis::find_file_details (GroupIDType parSetID, uint16_t parLevel, boost::string_ref parDir) {
|
||||
return std::vector<dinhelp::MaxSizedArray<std::string, 1>>();
|
||||
return dindb::find_file_details(m_redis, parSetID, parLevel, parDir);
|
||||
}
|
||||
|
||||
std::vector<std::string> BackendRedis::find_paths_starting_by (GroupIDType parGroupID, uint16_t parLevel, boost::string_ref parPath) {
|
||||
|
|
|
@ -144,6 +144,7 @@ namespace dindb {
|
|||
}
|
||||
|
||||
dele_batch.del(PROGRAM_NAME ":set:" + lexical_cast<std::string>(set_id));
|
||||
dele_batch.del(PROGRAM_NAME ":levels:" + lexical_cast<std::string>(set_id));
|
||||
chunked_run<FileIDType, 8>(dele_batch.batch(), +"DEL", file_base_index, file_count, [](FileIDType id){return PROGRAM_NAME ":file:" + lexical_cast<std::string>(id);});
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <functional>
|
||||
#include <iterator>
|
||||
#include <cstdint>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
|
||||
namespace dindb {
|
||||
namespace {
|
||||
|
@ -261,7 +262,6 @@ namespace dindb {
|
|||
|
||||
std::vector<dinhelp::MaxSizedArray<std::string, 4>> find_set_details (redis::IncRedis& parRedis, const std::vector<GroupIDType>& parSets) {
|
||||
using dinhelp::lexical_cast;
|
||||
using MArr = dinhelp::MaxSizedArray<std::string, 4>;
|
||||
|
||||
auto batch = parRedis.make_batch();
|
||||
for (auto set_id : parSets) {
|
||||
|
@ -270,7 +270,7 @@ namespace dindb {
|
|||
}
|
||||
batch.throw_if_failed();
|
||||
|
||||
std::vector<MArr> retval;
|
||||
std::vector<dinhelp::MaxSizedArray<std::string, 4>> retval;
|
||||
auto curr_set = parSets.begin();
|
||||
for (const auto& reply : batch.replies()) {
|
||||
const auto& reply_list = get_array(reply);
|
||||
|
@ -288,4 +288,33 @@ namespace dindb {
|
|||
}
|
||||
return retval;
|
||||
};
|
||||
|
||||
std::vector<dinhelp::MaxSizedArray<std::string, 1>> find_file_details (redis::IncRedis& parRedis, GroupIDType parSetID, uint16_t parLevel, boost::string_ref parDir) {
|
||||
using dinhelp::lexical_cast;
|
||||
using RetListType = std::vector<dinhelp::MaxSizedArray<std::string, 1>>;
|
||||
|
||||
const double level = static_cast<float>(parLevel);
|
||||
auto lst = parRedis.zrangebyscore(PROGRAM_NAME ":levels:" + lexical_cast<std::string>(parSetID), level, true, level, true, false);
|
||||
if (not lst)
|
||||
return RetListType();
|
||||
|
||||
auto batch = parRedis.make_batch();
|
||||
for (const auto& itm : *lst) {
|
||||
if (itm)
|
||||
batch.hget(*itm, "path");
|
||||
}
|
||||
batch.throw_if_failed();
|
||||
|
||||
std::vector<dinhelp::MaxSizedArray<std::string, 1>> retval;
|
||||
for (auto& reply : batch.replies()) {
|
||||
if (redis::RedisVariantType_Nil != reply.which()) {
|
||||
auto curr_path = get_string(reply);
|
||||
if (boost::starts_with(curr_path, parDir)) {
|
||||
retval.resize(retval.size() + 1);
|
||||
retval.back().push_back(std::move(curr_path));
|
||||
}
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
};
|
||||
} //namespace dindb
|
||||
|
|
|
@ -33,6 +33,7 @@ namespace dindb {
|
|||
std::vector<LocatedSet> locate_sets_in_db ( redis::IncRedis& parRedis, const std::string& parSubstr, bool parCaseInsensitive );
|
||||
std::vector<LocatedSet> locate_sets_in_db ( redis::IncRedis& parRedis, const std::string& parSubstr, const std::vector<GroupIDType>& parSets, bool parCaseInsensitive );
|
||||
std::vector<dinhelp::MaxSizedArray<std::string, 4>> find_set_details ( redis::IncRedis& parRedis, const std::vector<GroupIDType>& parSets );
|
||||
std::vector<dinhelp::MaxSizedArray<std::string, 1>> find_file_details ( redis::IncRedis& parRedis, GroupIDType parSetID, uint16_t parLevel, boost::string_ref parDir );
|
||||
} //namespace dindb
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue