mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-02-21 12:34:56 +00:00
Move tagging by id into a separate file.
This commit is contained in:
parent
7b77913b49
commit
9c2f1d7403
4 changed files with 141 additions and 16 deletions
|
@ -15,6 +15,7 @@ add_library(${PROJECT_NAME} SHARED
|
||||||
script.cpp
|
script.cpp
|
||||||
script_manager.cpp
|
script_manager.cpp
|
||||||
async_connection.cpp
|
async_connection.cpp
|
||||||
|
tag.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME} SYSTEM
|
target_include_directories(${PROJECT_NAME} SYSTEM
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "helpers/lexical_cast.hpp"
|
#include "helpers/lexical_cast.hpp"
|
||||||
#include "dindexerConfig.h"
|
#include "dindexerConfig.h"
|
||||||
#include "helpers/stringize.h"
|
#include "helpers/stringize.h"
|
||||||
|
#include "tag.hpp"
|
||||||
#include "record_data_adapt.hpp"
|
#include "record_data_adapt.hpp"
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <yaml-cpp/yaml.h>
|
#include <yaml-cpp/yaml.h>
|
||||||
|
@ -29,7 +30,6 @@
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <boost/range/empty.hpp>
|
#include <boost/range/empty.hpp>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
namespace dindb {
|
namespace dindb {
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -124,21 +124,7 @@ namespace dindb {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackendRedis::tag_files (const std::vector<FileIDType>& parFiles, const std::vector<boost::string_ref>& parTags, GroupIDType parSet) {
|
void BackendRedis::tag_files (const std::vector<FileIDType>& parFiles, const std::vector<boost::string_ref>& parTags, GroupIDType parSet) {
|
||||||
using dinhelp::lexical_cast;
|
dindb::tag_files(m_redis, m_tag_if_in_set, parFiles, parTags, parSet);
|
||||||
|
|
||||||
auto batch = m_redis.make_batch();
|
|
||||||
const std::string set_key = (parSet != InvalidGroupID ? PROGRAM_NAME ":set:" + 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 = PROGRAM_NAME ":file:" + lexical_cast<std::string>(file_id);
|
|
||||||
m_tag_if_in_set.run(batch, std::make_tuple(tag_key, file_key), std::make_tuple(set_key));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
batch.throw_if_failed();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackendRedis::tag_files (const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, GroupIDType parSet) {
|
void BackendRedis::tag_files (const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, GroupIDType parSet) {
|
||||||
|
|
63
src/backends/redis/tag.cpp
Normal file
63
src/backends/redis/tag.cpp
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
/* Copyright 2015, 2016, Michele Santullo
|
||||||
|
* This file is part of "dindexer".
|
||||||
|
*
|
||||||
|
* "dindexer" is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* "dindexer" is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "tag.hpp"
|
||||||
|
#include "command.hpp"
|
||||||
|
#include "dindexerConfig.h"
|
||||||
|
#include "helpers/lexical_cast.hpp"
|
||||||
|
#include <sstream>
|
||||||
|
#include <tuple>
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
|
namespace dindb {
|
||||||
|
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) {
|
||||||
|
using dinhelp::lexical_cast;
|
||||||
|
|
||||||
|
auto batch = parRedis.make_batch();
|
||||||
|
const std::string set_key = (parSet != InvalidGroupID ? PROGRAM_NAME ":set:" + 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 = PROGRAM_NAME ":file:" + lexical_cast<std::string>(file_id);
|
||||||
|
parTagIfInSet.run(batch, std::make_tuple(tag_key, file_key), std::make_tuple(set_key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
batch.throw_if_failed();
|
||||||
|
}
|
||||||
|
|
||||||
|
void tag_files (redis::Command& parRedis, redis::Script& parTagIfInSet, const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, GroupIDType 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<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, GroupIDType 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<std::string>& parRegexes, GroupIDType parSet) {
|
||||||
|
}
|
||||||
|
} //namespace dindb
|
||||||
|
|
75
src/backends/redis/tag.hpp
Normal file
75
src/backends/redis/tag.hpp
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
/* Copyright 2015, 2016, Michele Santullo
|
||||||
|
* This file is part of "dindexer".
|
||||||
|
*
|
||||||
|
* "dindexer" is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* "dindexer" is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef id2874EA620CF0415CAF5B005E227BC44B
|
||||||
|
#define id2874EA620CF0415CAF5B005E227BC44B
|
||||||
|
|
||||||
|
#include "backends/db_backend.hpp"
|
||||||
|
#include <vector>
|
||||||
|
#include <boost/utility/string_ref.hpp>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
|
namespace redis {
|
||||||
|
class Command;
|
||||||
|
class Script;
|
||||||
|
} //namespace redis
|
||||||
|
|
||||||
|
namespace dindb {
|
||||||
|
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<std::string>& parRegexes,
|
||||||
|
const std::vector<boost::string_ref>& parTags,
|
||||||
|
GroupIDType 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<std::string>& parRegexes,
|
||||||
|
const std::vector<boost::string_ref>& parTags,
|
||||||
|
GroupIDType 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<std::string>& parRegexes,
|
||||||
|
GroupIDType parSet
|
||||||
|
);
|
||||||
|
} //namespace dindb
|
||||||
|
|
||||||
|
#endif
|
Loading…
Add table
Reference in a new issue