1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2025-02-21 12:34:56 +00:00

Use GroupIDType and FileIDType instead of uint.

This commit is contained in:
King_DuckZ 2016-07-11 17:46:08 +01:00
parent bd06158d4c
commit e5007cf96f
6 changed files with 18 additions and 20 deletions

View file

@ -29,7 +29,7 @@
namespace dindb { namespace dindb {
namespace { namespace {
IDDescMap fetch_existing_ids (pq::Connection& parConn, const std::vector<uint32_t>& parIDs) { IDDescMap fetch_existing_ids (pq::Connection& parConn, const std::vector<GroupIDType>& parIDs) {
using boost::lexical_cast; using boost::lexical_cast;
IDDescMap retmap; IDDescMap retmap;
@ -39,7 +39,7 @@ namespace dindb {
std::ostringstream oss; std::ostringstream oss;
oss << "SELECT \"id\",\"desc\" FROM \"sets\" WHERE \"id\"="; oss << "SELECT \"id\",\"desc\" FROM \"sets\" WHERE \"id\"=";
boost::copy(parIDs, infix_ostream_iterator<uint32_t>(oss, " OR \"id\"=")); boost::copy(parIDs, infix_ostream_iterator<GroupIDType>(oss, " OR \"id\"="));
oss << ';'; oss << ';';
auto resultset = parConn.query(oss.str()); auto resultset = parConn.query(oss.str());
@ -50,7 +50,7 @@ namespace dindb {
} }
} //unnamed namespace } //unnamed namespace
void delete_group_from_db (pq::Connection& parDB, const std::vector<uint32_t>& parIDs, ConfirmDeleCallback parConf) { void delete_group_from_db (pq::Connection& parDB, const std::vector<GroupIDType>& parIDs, ConfirmDeleCallback parConf) {
assert(parDB.is_connected()); assert(parDB.is_connected());
const auto dele_ids = fetch_existing_ids(parDB, parIDs); const auto dele_ids = fetch_existing_ids(parDB, parIDs);
@ -65,9 +65,9 @@ namespace dindb {
ids.reserve(dele_ids.size()); ids.reserve(dele_ids.size());
std::ostringstream oss; std::ostringstream oss;
oss << "BEGIN;\nDELETE FROM \"files\" WHERE \"group_id\"="; oss << "BEGIN;\nDELETE FROM \"files\" WHERE \"group_id\"=";
boost::copy(dele_ids | boost::adaptors::map_keys, infix_ostream_iterator<uint32_t>(oss, " OR \"group_id\"=")); boost::copy(dele_ids | boost::adaptors::map_keys, infix_ostream_iterator<GroupIDType>(oss, " OR \"group_id\"="));
oss << ";\nDELETE FROM \"sets\" WHERE \"id\"="; oss << ";\nDELETE FROM \"sets\" WHERE \"id\"=";
boost::copy(dele_ids | boost::adaptors::map_keys, infix_ostream_iterator<uint32_t>(oss, " OR \"id\"=")); boost::copy(dele_ids | boost::adaptors::map_keys, infix_ostream_iterator<GroupIDType>(oss, " OR \"id\"="));
oss << ";\nCOMMIT;"; oss << ";\nCOMMIT;";
parDB.query(oss.str()); parDB.query(oss.str());

View file

@ -22,7 +22,6 @@
#include <functional> #include <functional>
#include <vector> #include <vector>
#include <string> #include <string>
#include <cstdint>
#include <map> #include <map>
namespace pq { namespace pq {
@ -30,10 +29,10 @@ namespace pq {
} //namespace pq } //namespace pq
namespace dindb { namespace dindb {
using IDDescMap = std::map<uint32_t, std::string>; using IDDescMap = std::map<GroupIDType, std::string>;
using ConfirmDeleCallback = std::function<bool(const IDDescMap&)>; using ConfirmDeleCallback = std::function<bool(const IDDescMap&)>;
void delete_group_from_db ( pq::Connection& parDB, const std::vector<uint32_t>& parIDs, ConfirmDeleCallback parConf ); void delete_group_from_db ( pq::Connection& parDB, const std::vector<GroupIDType>& parIDs, ConfirmDeleCallback parConf );
} //namespace dindb } //namespace dindb
#endif #endif

View file

@ -148,7 +148,7 @@ namespace dindb {
dindb::delete_all_tags(m_redis, m_dele_tag_if_in_set, parRegexes, parSet); dindb::delete_all_tags(m_redis, m_dele_tag_if_in_set, parRegexes, parSet);
} }
void BackendRedis::delete_group (const std::vector<uint32_t>& parIDs, ConfirmDeleCallback parConf) { void BackendRedis::delete_group (const std::vector<GroupIDType>& parIDs, ConfirmDeleCallback parConf) {
} }
void BackendRedis::write_files (const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordDataFull& parSetData, const std::string& parSignature) { void BackendRedis::write_files (const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordDataFull& parSetData, const std::string& parSignature) {

View file

@ -42,7 +42,7 @@ namespace dindb {
virtual void delete_all_tags ( const std::vector<FileIDType>& parFiles, GroupIDType parSet ) override; virtual void delete_all_tags ( const std::vector<FileIDType>& parFiles, GroupIDType parSet ) override;
virtual void delete_all_tags ( const std::vector<std::string>& parRegexes, GroupIDType parSet ) override; virtual void delete_all_tags ( const std::vector<std::string>& parRegexes, GroupIDType parSet ) override;
virtual void delete_group ( const std::vector<uint32_t>& parIDs, ConfirmDeleCallback parConf ) override; virtual void delete_group ( const std::vector<GroupIDType>& parIDs, ConfirmDeleCallback parConf ) override;
virtual void write_files ( const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordDataFull& parSetData, const std::string& parSignature ) override; virtual void write_files ( const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordDataFull& parSetData, const std::string& parSignature ) override;
virtual bool search_file_by_hash ( mchlib::FileRecordData& parItem, mchlib::SetRecordDataFull& parSet, const mchlib::TigerHash& parHash ) override; virtual bool search_file_by_hash ( mchlib::FileRecordData& parItem, mchlib::SetRecordDataFull& parSet, const mchlib::TigerHash& parHash ) override;

View file

@ -37,7 +37,7 @@ namespace std {
namespace dindb { namespace dindb {
namespace { namespace {
std::string make_file_key (uint64_t parID) { std::string make_file_key (FileIDType parID) {
return PROGRAM_NAME ":file:" + dinhelp::lexical_cast<std::string>(parID); return PROGRAM_NAME ":file:" + dinhelp::lexical_cast<std::string>(parID);
} }
@ -54,7 +54,7 @@ namespace dindb {
return retval; return retval;
} }
void run_id_based_script (redis::Command& parRedis, redis::Script& parScript, const std::vector<uint64_t>& parFiles, const std::vector<boost::string_ref>& parTags, GroupIDType parSet) { void run_id_based_script (redis::Command& parRedis, redis::Script& parScript, const std::vector<FileIDType>& parFiles, const std::vector<boost::string_ref>& parTags, GroupIDType parSet) {
using dinhelp::lexical_cast; using dinhelp::lexical_cast;
auto batch = parRedis.make_batch(); auto batch = parRedis.make_batch();
@ -105,7 +105,7 @@ namespace dindb {
} }
} //unnamed namespace } //unnamed namespace
void tag_files (redis::Command& parRedis, redis::Script& parTagIfInSet, const std::vector<uint64_t>& parFiles, const std::vector<boost::string_ref>& parTags, GroupIDType parSet) { void tag_files (redis::Command& parRedis, redis::Script& parTagIfInSet, const std::vector<FileIDType>& parFiles, const std::vector<boost::string_ref>& parTags, GroupIDType parSet) {
run_id_based_script(parRedis, parTagIfInSet, parFiles, parTags, parSet); run_id_based_script(parRedis, parTagIfInSet, parFiles, parTags, parSet);
} }
@ -113,7 +113,7 @@ namespace dindb {
run_regex_based_script(parRedis, parTagIfInSet, parRegexes, parTags, parSet); run_regex_based_script(parRedis, parTagIfInSet, parRegexes, parTags, parSet);
} }
void delete_tags (redis::Command& parRedis, redis::Script& parDeleIfInSet, const std::vector<uint64_t>& parFiles, const std::vector<boost::string_ref>& parTags, GroupIDType parSet) { void delete_tags (redis::Command& parRedis, redis::Script& parDeleIfInSet, const std::vector<FileIDType>& parFiles, const std::vector<boost::string_ref>& parTags, GroupIDType parSet) {
run_id_based_script(parRedis, parDeleIfInSet, parFiles, parTags, parSet); run_id_based_script(parRedis, parDeleIfInSet, parFiles, parTags, parSet);
} }
@ -121,7 +121,7 @@ namespace dindb {
run_regex_based_script(parRedis, parDeleIfInSet, parRegexes, parTags, parSet); run_regex_based_script(parRedis, parDeleIfInSet, parRegexes, parTags, parSet);
} }
void delete_all_tags (redis::Command& parRedis, redis::Script& parDeleIfInSet, const std::vector<uint64_t>& parFiles, GroupIDType parSet) { void delete_all_tags (redis::Command& parRedis, redis::Script& parDeleIfInSet, const std::vector<FileIDType>& parFiles, GroupIDType parSet) {
auto batch = parRedis.make_batch(); auto batch = parRedis.make_batch();
for (const auto file_id : parFiles) { for (const auto file_id : parFiles) {
const auto file_key = make_file_key(file_id); const auto file_key = make_file_key(file_id);
@ -147,7 +147,7 @@ namespace dindb {
const auto regexes = compile_regexes(parRegexes); const auto regexes = compile_regexes(parRegexes);
std::set<std::string> dele_tags; std::set<std::string> dele_tags;
std::vector<uint64_t> ids; std::vector<FileIDType> ids;
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;

View file

@ -21,7 +21,6 @@
#include "backends/db_backend.hpp" #include "backends/db_backend.hpp"
#include <vector> #include <vector>
#include <boost/utility/string_ref.hpp> #include <boost/utility/string_ref.hpp>
#include <cstdint>
namespace redis { namespace redis {
class Command; class Command;
@ -32,7 +31,7 @@ namespace dindb {
void tag_files ( void tag_files (
redis::Command& parRedis, redis::Command& parRedis,
redis::Script& parTagIfInSet, redis::Script& parTagIfInSet,
const std::vector<uint64_t>& parFiles, const std::vector<FileIDType>& parFiles,
const std::vector<boost::string_ref>& parTags, const std::vector<boost::string_ref>& parTags,
GroupIDType parSet GroupIDType parSet
); );
@ -47,7 +46,7 @@ namespace dindb {
void delete_tags ( void delete_tags (
redis::Command& parRedis, redis::Command& parRedis,
redis::Script& parDeleIfInSet, redis::Script& parDeleIfInSet,
const std::vector<uint64_t>& parFiles, const std::vector<FileIDType>& parFiles,
const std::vector<boost::string_ref>& parTags, const std::vector<boost::string_ref>& parTags,
GroupIDType parSet GroupIDType parSet
); );
@ -61,7 +60,7 @@ namespace dindb {
void delete_all_tags ( void delete_all_tags (
redis::Command& parRedis, redis::Command& parRedis,
redis::Script& parDeleIfInSet, redis::Script& parDeleIfInSet,
const std::vector<uint64_t>& parFiles, const std::vector<FileIDType>& parFiles,
GroupIDType parSet GroupIDType parSet
); );
void delete_all_tags ( void delete_all_tags (