1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2025-02-19 12:04:54 +00:00

Move tagging by id into a separate file.

This commit is contained in:
King_DuckZ 2016-07-10 13:59:45 +01:00
parent 7b77913b49
commit 9c2f1d7403
4 changed files with 141 additions and 16 deletions

View file

@ -15,6 +15,7 @@ add_library(${PROJECT_NAME} SHARED
script.cpp
script_manager.cpp
async_connection.cpp
tag.cpp
)
target_include_directories(${PROJECT_NAME} SYSTEM

View file

@ -22,6 +22,7 @@
#include "helpers/lexical_cast.hpp"
#include "dindexerConfig.h"
#include "helpers/stringize.h"
#include "tag.hpp"
#include "record_data_adapt.hpp"
#include <utility>
#include <yaml-cpp/yaml.h>
@ -29,7 +30,6 @@
#include <cstdint>
#include <boost/range/empty.hpp>
#include <fstream>
#include <sstream>
namespace dindb {
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) {
using dinhelp::lexical_cast;
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();
dindb::tag_files(m_redis, m_tag_if_in_set, parFiles, parTags, parSet);
}
void BackendRedis::tag_files (const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, GroupIDType parSet) {

View 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

View 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