mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2024-11-25 00:53:43 +00:00
Fix tagging.
Tag functions are now fully available through the new plugin.
This commit is contained in:
parent
c009c07c9d
commit
df2e04a029
5 changed files with 79 additions and 87 deletions
|
@ -36,12 +36,12 @@ namespace dindb {
|
|||
Backend ( void ) = default;
|
||||
virtual ~Backend ( void ) noexcept = default;
|
||||
|
||||
virtual void tag_files ( const std::vector<FileIDType>& parFiles, const std::vector<boost::string_ref>& parTags, GroupIDType parSet ) const = 0;
|
||||
virtual void tag_files ( const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, GroupIDType parSet ) const = 0;
|
||||
virtual void delete_tags ( const std::vector<FileIDType>& parFiles, const std::vector<boost::string_ref>& parTags, GroupIDType parSet ) const = 0;
|
||||
virtual void delete_tags ( const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, GroupIDType parSet ) const = 0;
|
||||
virtual void delete_all_tags ( const std::vector<FileIDType>& parFiles, GroupIDType parSet ) const = 0;
|
||||
virtual void delete_all_tags ( const std::vector<std::string>& parRegexes, GroupIDType parSet ) const = 0;
|
||||
virtual void tag_files ( const std::vector<FileIDType>& parFiles, const std::vector<boost::string_ref>& parTags, GroupIDType parSet ) = 0;
|
||||
virtual void tag_files ( const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, GroupIDType parSet ) = 0;
|
||||
virtual void delete_tags ( const std::vector<FileIDType>& parFiles, const std::vector<boost::string_ref>& parTags, GroupIDType parSet ) = 0;
|
||||
virtual void delete_tags ( const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, GroupIDType parSet ) = 0;
|
||||
virtual void delete_all_tags ( const std::vector<FileIDType>& parFiles, GroupIDType parSet ) = 0;
|
||||
virtual void delete_all_tags ( const std::vector<std::string>& parRegexes, GroupIDType parSet ) = 0;
|
||||
|
||||
};
|
||||
} //namespace dindb
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include "backend_postgresql.hpp"
|
||||
#include "backends/exposed_functions.hpp"
|
||||
#include "tag.hpp"
|
||||
#include "pq/connection.hpp"
|
||||
#include <ciso646>
|
||||
#include <utility>
|
||||
|
@ -75,32 +76,28 @@ namespace dindb {
|
|||
m_conn->disconnect();
|
||||
}
|
||||
|
||||
void BackendPostgreSql::tag_files (const std::vector<FileIDType>& parFiles, const std::vector<boost::string_ref>& parTags, GroupIDType parSet) const {
|
||||
if (InvalidGroupID != parSet) {
|
||||
const std::string query =
|
||||
"UPDATE \"files\" SET \"tags\" = ARRAY(SELECT DISTINCT UNNEST(\"tags\" || $1) ORDER BY 1) WHERE \"id\"=ANY($2) AND \"group_id\"=$3;";
|
||||
m_conn->query(query, parTags, parFiles, parSet);
|
||||
}
|
||||
else {
|
||||
const std::string query =
|
||||
"UPDATE \"files\" SET \"tags\" = ARRAY(SELECT DISTINCT UNNEST(\"tags\" || $1) ORDER BY 1) WHERE \"id\"=ANY($2);";
|
||||
m_conn->query(query, parTags, parFiles);
|
||||
}
|
||||
void BackendPostgreSql::tag_files (const std::vector<FileIDType>& parFiles, const std::vector<boost::string_ref>& parTags, GroupIDType parSet) {
|
||||
dindb::tag_files(*m_conn, parFiles, parTags, parSet);
|
||||
}
|
||||
|
||||
void BackendPostgreSql::tag_files (const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, GroupIDType parSet) const {
|
||||
void BackendPostgreSql::tag_files (const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, GroupIDType parSet) {
|
||||
dindb::tag_files(*m_conn, parRegexes, parTags, parSet);
|
||||
}
|
||||
|
||||
void BackendPostgreSql::delete_tags (const std::vector<FileIDType>& parFiles, const std::vector<boost::string_ref>& parTags, GroupIDType parSet) const {
|
||||
void BackendPostgreSql::delete_tags (const std::vector<FileIDType>& parFiles, const std::vector<boost::string_ref>& parTags, GroupIDType parSet) {
|
||||
dindb::delete_tags(*m_conn, parFiles, parTags, parSet);
|
||||
}
|
||||
|
||||
void BackendPostgreSql::delete_tags (const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, GroupIDType parSet) const {
|
||||
void BackendPostgreSql::delete_tags (const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, GroupIDType parSet) {
|
||||
dindb::delete_tags(*m_conn, parRegexes, parTags, parSet);
|
||||
}
|
||||
|
||||
void BackendPostgreSql::delete_all_tags (const std::vector<FileIDType>& parFiles, GroupIDType parSet) const {
|
||||
void BackendPostgreSql::delete_all_tags (const std::vector<FileIDType>& parFiles, GroupIDType parSet) {
|
||||
dindb::delete_all_tags(*m_conn, parFiles, parSet);
|
||||
}
|
||||
|
||||
void BackendPostgreSql::delete_all_tags (const std::vector<std::string>& parRegexes, GroupIDType parSet) const {
|
||||
void BackendPostgreSql::delete_all_tags (const std::vector<std::string>& parRegexes, GroupIDType parSet) {
|
||||
dindb::delete_all_tags(*m_conn, parRegexes, parSet);
|
||||
}
|
||||
} //namespace dindb
|
||||
|
||||
|
|
|
@ -34,12 +34,12 @@ namespace dindb {
|
|||
BackendPostgreSql ( std::string&& parUser, std::string&& parPass, std::string&& parDB, std::string&& parAddr, uint16_t parPort );
|
||||
virtual ~BackendPostgreSql ( void ) noexcept;
|
||||
|
||||
virtual void tag_files ( const std::vector<FileIDType>& parFiles, const std::vector<boost::string_ref>& parTags, GroupIDType parSet ) const override;
|
||||
virtual void tag_files ( const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, GroupIDType parSet ) const override;
|
||||
virtual void delete_tags ( const std::vector<FileIDType>& parFiles, const std::vector<boost::string_ref>& parTags, GroupIDType parSet ) const override;
|
||||
virtual void delete_tags ( const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, GroupIDType parSet ) const override;
|
||||
virtual void delete_all_tags ( const std::vector<FileIDType>& parFiles, GroupIDType parSet ) const override;
|
||||
virtual void delete_all_tags ( const std::vector<std::string>& parRegexes, GroupIDType parSet ) const override;
|
||||
virtual void tag_files ( const std::vector<FileIDType>& parFiles, const std::vector<boost::string_ref>& parTags, GroupIDType parSet ) override;
|
||||
virtual void tag_files ( const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, GroupIDType parSet ) override;
|
||||
virtual void delete_tags ( const std::vector<FileIDType>& parFiles, const std::vector<boost::string_ref>& parTags, GroupIDType parSet ) override;
|
||||
virtual void delete_tags ( const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, 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;
|
||||
|
||||
private:
|
||||
std::unique_ptr<pq::Connection> m_conn;
|
||||
|
|
|
@ -15,141 +15,135 @@
|
|||
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "db/tag.hpp"
|
||||
#include "db/settings.hpp"
|
||||
#include "tag.hpp"
|
||||
#include "pq/connection.hpp"
|
||||
#include <ciso646>
|
||||
#include <cassert>
|
||||
|
||||
namespace dindb {
|
||||
void tag_files (const Settings& parDB, const std::vector<uint64_t>& parFiles, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet) {
|
||||
pq::Connection conn(std::string(parDB.username), std::string(parDB.password), std::string(parDB.dbname), std::string(parDB.address), parDB.port);
|
||||
conn.connect();
|
||||
void tag_files (pq::Connection& parDB, const std::vector<uint64_t>& parFiles, const std::vector<boost::string_ref>& parTags, GroupIDType parSet) {
|
||||
assert(parDB.is_connected());
|
||||
|
||||
if (parSet.is_valid) {
|
||||
if (InvalidGroupID != parSet) {
|
||||
const std::string query =
|
||||
"UPDATE \"files\" SET \"tags\" = ARRAY(SELECT DISTINCT UNNEST(\"tags\" || $1) ORDER BY 1) WHERE \"id\"=ANY($2) AND \"group_id\"=$3;";
|
||||
conn.query(query, parTags, parFiles, parSet.group_id);
|
||||
parDB.query(query, parTags, parFiles, parSet);
|
||||
}
|
||||
else {
|
||||
const std::string query =
|
||||
"UPDATE \"files\" SET \"tags\" = ARRAY(SELECT DISTINCT UNNEST(\"tags\" || $1) ORDER BY 1) WHERE \"id\"=ANY($2);";
|
||||
conn.query(query, parTags, parFiles);
|
||||
parDB.query(query, parTags, parFiles);
|
||||
}
|
||||
}
|
||||
|
||||
void tag_files (const Settings& parDB, const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet) {
|
||||
pq::Connection conn(std::string(parDB.username), std::string(parDB.password), std::string(parDB.dbname), std::string(parDB.address), parDB.port);
|
||||
conn.connect();
|
||||
void tag_files (pq::Connection& parDB, const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, GroupIDType parSet) {
|
||||
assert(parDB.is_connected());
|
||||
|
||||
if (parSet.is_valid) {
|
||||
if (InvalidGroupID != parSet) {
|
||||
if (parRegexes.size() == 1) {
|
||||
const std::string query = "UPDATE \"files\" SET \"tags\" = ARRAY(SELECT DISTINCT UNNEST(\"tags\" || $1) ORDER BY 1) WHERE \"group_id\"=$2 AND \"path\" ~ $3;";
|
||||
conn.query(query, parTags, parSet.group_id, parRegexes.front());
|
||||
parDB.query(query, parTags, parSet, parRegexes.front());
|
||||
}
|
||||
else if (parRegexes.size() > 1) {
|
||||
const std::string query = "UPDATE \"files\" SET \"tags\" = ARRAY(SELECT DISTINCT UNNEST(\"tags\" || $1) ORDER BY 1) WHERE \"group_id\"=$2 AND \"path\" ~ ANY($3);";
|
||||
conn.query(query, parTags, parSet.group_id, parRegexes);
|
||||
parDB.query(query, parTags, parSet, parRegexes);
|
||||
}
|
||||
else if (parRegexes.size() == 0) {
|
||||
const std::string query = "UPDATE \"files\" SET \"tags\" = ARRAY(SELECT DISTINCT UNNEST(\"tags\" || $1) WHERE \"group_id\"=$2 ORDER BY 1);";
|
||||
conn.query(query, parTags, parSet.group_id);
|
||||
parDB.query(query, parTags, parSet);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (parRegexes.size() == 1) {
|
||||
const std::string query = "UPDATE \"files\" SET \"tags\" = ARRAY(SELECT DISTINCT UNNEST(\"tags\" || $1) ORDER BY 1) WHERE \"path\" ~ $2;";
|
||||
conn.query(query, parTags, parRegexes.front());
|
||||
parDB.query(query, parTags, parRegexes.front());
|
||||
}
|
||||
else if (parRegexes.size() > 1) {
|
||||
const std::string query = "UPDATE \"files\" SET \"tags\" = ARRAY(SELECT DISTINCT UNNEST(\"tags\" || $1) ORDER BY 1) WHERE \"path\" ~ ANY($2);";
|
||||
conn.query(query, parTags, parRegexes);
|
||||
parDB.query(query, parTags, parRegexes);
|
||||
}
|
||||
else if (parRegexes.size() == 0) {
|
||||
const std::string query = "UPDATE \"files\" SET \"tags\" = ARRAY(SELECT DISTINCT UNNEST(\"tags\" || $1) ORDER BY 1);";
|
||||
conn.query(query, parTags);
|
||||
parDB.query(query, parTags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void delete_tags (const Settings& parDB, const std::vector<uint64_t>& parFiles, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet) {
|
||||
pq::Connection conn(std::string(parDB.username), std::string(parDB.password), std::string(parDB.dbname), std::string(parDB.address), parDB.port);
|
||||
conn.connect();
|
||||
void delete_tags (pq::Connection& parDB, const std::vector<uint64_t>& parFiles, const std::vector<boost::string_ref>& parTags, GroupIDType parSet) {
|
||||
assert(parDB.is_connected());
|
||||
|
||||
if (parTags.size() == 1) {
|
||||
if (parSet.is_valid) {
|
||||
if (InvalidGroupID != parSet) {
|
||||
const std::string query = "UPDATE \"files\" SET \"tags\" = ARRAY_REMOVE(tags, $1) WHERE \"id\" = ANY($2) AND \"group_id\" = $3;";
|
||||
conn.query(query, parTags.front(), parFiles, parSet.group_id);
|
||||
parDB.query(query, parTags.front(), parFiles, parSet);
|
||||
}
|
||||
else {
|
||||
const std::string query = "UPDATE \"files\" SET \"tags\" = ARRAY_REMOVE(tags, $1) WHERE \"id\" = ANY($2);";
|
||||
conn.query(query, parTags.front(), parFiles);
|
||||
parDB.query(query, parTags.front(), parFiles);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (parSet.is_valid) {
|
||||
if (InvalidGroupID != parSet) {
|
||||
const std::string query = "UPDATE \"files\" SET \"tags\" = ARRAY(SELECT UNNEST(\"tags\") EXCEPT SELECT UNNEST($1)) WHERE \"id\" = ANY($2) AND \"group_id\" = $3;";
|
||||
conn.query(query, parTags, parFiles, parSet.group_id);
|
||||
parDB.query(query, parTags, parFiles, parSet);
|
||||
}
|
||||
else {
|
||||
const std::string query = "UPDATE \"files\" SET \"tags\" = ARRAY(SELECT UNNEST(\"tags\") EXCEPT SELECT UNNEST($1)) WHERE \"id\" = ANY($2);";
|
||||
conn.query(query, parTags, parFiles);
|
||||
parDB.query(query, parTags, parFiles);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void delete_tags (const Settings& parDB, const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet) {
|
||||
pq::Connection conn(std::string(parDB.username), std::string(parDB.password), std::string(parDB.dbname), std::string(parDB.address), parDB.port);
|
||||
conn.connect();
|
||||
void delete_tags (pq::Connection& parDB, const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, GroupIDType parSet) {
|
||||
assert(parDB.is_connected());
|
||||
|
||||
if (parTags.size() == 1) {
|
||||
if (parSet.is_valid) {
|
||||
if (InvalidGroupID != parSet) {
|
||||
const std::string query = "UPDATE \"files\" SET \"tags\" = ARRAY_REMOVE(tags, $1) WHERE \"group_id\" = $3 AND \"path\" ~ ANY($3);";
|
||||
conn.query(query, parTags.front(), parSet.group_id, parRegexes);
|
||||
parDB.query(query, parTags.front(), parSet, parRegexes);
|
||||
}
|
||||
else {
|
||||
const std::string query = "UPDATE \"files\" SET \"tags\" = ARRAY_REMOVE(tags, $1) WHERE \"path\" ~ ANY($2);";
|
||||
conn.query(query, parTags.front(), parRegexes);
|
||||
parDB.query(query, parTags.front(), parRegexes);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (parSet.is_valid) {
|
||||
if (InvalidGroupID != parSet) {
|
||||
const std::string query = "UPDATE \"files\" SET \"tags\" = ARRAY(SELECT UNNEST(\"tags\") EXCEPT SELECT UNNEST($1)) WHERE \"group_id\" = $2 AND \"path\" ~ ANY($3);";
|
||||
conn.query(query, parTags, parSet.group_id, parRegexes);
|
||||
parDB.query(query, parTags, parSet, parRegexes);
|
||||
}
|
||||
else {
|
||||
const std::string query = "UPDATE \"files\" SET \"tags\" = ARRAY(SELECT UNNEST(\"tags\") EXCEPT SELECT UNNEST($1)) WHERE \"path\" = ANY($2);";
|
||||
conn.query(query, parTags, parRegexes);
|
||||
parDB.query(query, parTags, parRegexes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void delete_all_tags (const Settings& parDB, const std::vector<uint64_t>& parFiles, OwnerSetInfo parSet) {
|
||||
pq::Connection conn(std::string(parDB.username), std::string(parDB.password), std::string(parDB.dbname), std::string(parDB.address), parDB.port);
|
||||
conn.connect();
|
||||
void delete_all_tags (pq::Connection& parDB, const std::vector<uint64_t>& parFiles, GroupIDType parSet) {
|
||||
assert(parDB.is_connected());
|
||||
|
||||
if (parSet.is_valid) {
|
||||
if (InvalidGroupID != parSet) {
|
||||
const std::string query =
|
||||
"UPDATE \"files\" SET \"tags\" = '{}' WHERE \"id\"=ANY($1) AND \"group_id\"=$2;";
|
||||
conn.query(query, parFiles, parSet.group_id);
|
||||
parDB.query(query, parFiles, parSet);
|
||||
}
|
||||
else {
|
||||
const std::string query =
|
||||
"UPDATE \"files\" SET \"tags\" = '{}' WHERE \"id\"=ANY($1);";
|
||||
conn.query(query, parFiles);
|
||||
parDB.query(query, parFiles);
|
||||
}
|
||||
}
|
||||
|
||||
void delete_all_tags (const Settings& parDB, const std::vector<std::string>& parRegexes, OwnerSetInfo parSet) {
|
||||
pq::Connection conn(std::string(parDB.username), std::string(parDB.password), std::string(parDB.dbname), std::string(parDB.address), parDB.port);
|
||||
conn.connect();
|
||||
void delete_all_tags (pq::Connection& parDB, const std::vector<std::string>& parRegexes, GroupIDType parSet) {
|
||||
assert(parDB.is_connected());
|
||||
|
||||
if (parSet.is_valid) {
|
||||
if (InvalidGroupID != parSet) {
|
||||
const std::string query = "UPDATE \"files\" SET \"tags\" = '{}' WHERE \"group_id\"=$1 AND \"path\" ~ ANY($2);";
|
||||
conn.query(query, parSet.group_id, parRegexes);
|
||||
parDB.query(query, parSet, parRegexes);
|
||||
}
|
||||
else {
|
||||
const std::string query = "UPDATE \"files\" SET \"tags\" = '{}' WHERE \"path\" ~ ANY($2);";
|
||||
conn.query(query, parRegexes);
|
||||
parDB.query(query, parRegexes);
|
||||
}
|
||||
}
|
||||
} //namespace dindb
|
||||
|
|
|
@ -18,25 +18,26 @@
|
|||
#ifndef idE1E1650A8CAA4949BD6D4D58BF2599F5
|
||||
#define idE1E1650A8CAA4949BD6D4D58BF2599F5
|
||||
|
||||
#include "backends/db_backend.hpp"
|
||||
#include <vector>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <cstdint>
|
||||
#include <pq/connection.hpp>
|
||||
|
||||
namespace pq {
|
||||
class Connection;
|
||||
} //namespace pq
|
||||
|
||||
namespace dindb {
|
||||
struct Settings;
|
||||
|
||||
struct OwnerSetInfo {
|
||||
uint32_t group_id;
|
||||
bool is_valid;
|
||||
};
|
||||
void tag_files ( pq::Connection& parDB, const std::vector<uint64_t>& parFiles, const std::vector<boost::string_ref>& parTags, GroupIDType parSet );
|
||||
void tag_files ( pq::Connection& parDB, const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, GroupIDType parSet );
|
||||
|
||||
void tag_files ( const Settings& parDB, const std::vector<uint64_t>& parFiles, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet );
|
||||
void tag_files ( const Settings& parDB, const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet );
|
||||
|
||||
void delete_tags ( const Settings& parDB, const std::vector<uint64_t>& parFiles, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet );
|
||||
void delete_tags ( const Settings& parDB, const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet );
|
||||
void delete_all_tags ( const Settings& parDB, const std::vector<uint64_t>& parFiles, OwnerSetInfo parSet );
|
||||
void delete_all_tags ( const Settings& parDB, const std::vector<std::string>& parRegexes, OwnerSetInfo parSet );
|
||||
void delete_tags ( pq::Connection& parDB, const std::vector<uint64_t>& parFiles, const std::vector<boost::string_ref>& parTags, GroupIDType parSet );
|
||||
void delete_tags ( pq::Connection& parDB, const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, GroupIDType parSet );
|
||||
void delete_all_tags ( pq::Connection& parDB, const std::vector<uint64_t>& parFiles, GroupIDType parSet );
|
||||
void delete_all_tags ( pq::Connection& parDB, const std::vector<std::string>& parRegexes, GroupIDType parSet );
|
||||
} //namespace dindb
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue