aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--signature_db.cpp28
-rw-r--r--signature_db.hpp2
-rw-r--r--tests/testdrive_sqlite.cpp2
3 files changed, 28 insertions, 4 deletions
diff --git a/signature_db.cpp b/signature_db.cpp
index 429581d..393b756 100644
--- a/signature_db.cpp
+++ b/signature_db.cpp
@@ -14,6 +14,7 @@ const int SIGDB_VERSION = 3;
enum batch_status
{
none = 0,
+ getsig,
putsub,
findsub,
setpar,
@@ -169,11 +170,20 @@ size_t signature_db::put_signature(const fs::path &path, const signature &sig,si
return static_cast<size_t>(sqlite3_last_insert_rowid(p->db));
}
+void signature_db::batch_get_signature_begin()
+{
+ if (!p->db) [[ unlikely ]] return;
+ sqlite3_prepare_v2(p->db, "select path, signature from images where id = ?;", -1, &p->bst[batch_status::getsig], 0);
+}
+
std::pair<fs::path, signature> signature_db::get_signature(size_t id)
{
if (!p->db) [[ unlikely ]] return std::make_pair(fs::path(), signature());
- sqlite3_stmt *st;
- sqlite3_prepare_v2(p->db, "select path, signature from images where id = ?;", -1, &st, 0);
+ sqlite3_stmt *st = nullptr;
+ if (p->bst[batch_status::getsig])
+ st = p->bst[batch_status::getsig];
+ else
+ sqlite3_prepare_v2(p->db, "select path, signature from images where id = ?;", -1, &st, 0);
sqlite3_bind_int(st, 1, id);
int rr = sqlite3_step(st);
if (rr == SQLITE_ROW)
@@ -184,15 +194,25 @@ std::pair<fs::path, signature> signature_db::get_signature(size_t id)
fs::path path((char*)sqlite3_column_text(st, 0));
#endif
std::string sigs((char*)sqlite3_column_text(st, 1));
- sqlite3_finalize(st);
+ if (p->bst[batch_status::getsig])
+ sqlite3_reset(st);
+ else
+ sqlite3_finalize(st);
return std::make_pair(path, signature::from_string(std::move(sigs)));
}
else
{
- sqlite3_finalize(st);
+ if (p->bst[batch_status::getsig])
+ sqlite3_reset(st);
+ else
+ sqlite3_finalize(st);
return std::make_pair(fs::path(), signature());
}
}
+void signature_db::batch_get_signature_end()
+{
+ p->batch_end(batch_status::getsig);
+}
void signature_db::batch_put_subslice_begin()
{
diff --git a/signature_db.hpp b/signature_db.hpp
index a56ae1f..b37cf0a 100644
--- a/signature_db.hpp
+++ b/signature_db.hpp
@@ -52,8 +52,10 @@ public:
//if specificted, id must be unique
//treat automatically assigned id as arbitrary opaque integers
size_t put_signature(const fs::path &path, const signature &sig, size_t id = ~size_t(0));
+ void batch_get_signature_begin();
//get image signature from database
std::pair<fs::path, signature> get_signature(size_t id);
+ void batch_get_signature_end();
//place batch_put_subslice_begin() and batch_put_subslice_end() around a group of
//put_subslice() calls to improve performance
diff --git a/tests/testdrive_sqlite.cpp b/tests/testdrive_sqlite.cpp
index c9e9aad..66d1996 100644
--- a/tests/testdrive_sqlite.cpp
+++ b/tests/testdrive_sqlite.cpp
@@ -229,6 +229,7 @@ int main(int argc,char** argv)
puts("grouping similar images...");
sdb->group_similar();
+ sdb->batch_get_signature_begin();
std::vector<dupe_t> dupes = sdb->dupe_pairs();
for (auto &p : dupes)
{
@@ -258,6 +259,7 @@ int main(int argc,char** argv)
#endif
}
}
+ sdb->batch_get_signature_end();
sdb->to_db_file("test.sigdb");
delete sdb;