From c43051df12f31796b54bbd36f96b70000fcaac17 Mon Sep 17 00:00:00 2001 From: Christian Hohnstaedt Date: Mon, 9 Apr 2018 06:09:55 +0200 Subject: [PATCH] Improve Use counter acquirement by one SQL statement for all keys --- lib/db_key.cpp | 21 +++++++++++++++++++++ lib/db_key.h | 1 + lib/pki_key.h | 4 ++++ 3 files changed, 26 insertions(+) diff --git a/lib/db_key.cpp b/lib/db_key.cpp index 341fccbb..504f2fec 100644 --- a/lib/db_key.cpp +++ b/lib/db_key.cpp @@ -38,6 +38,27 @@ db_key::db_key(MainWindow *mw) loadContainer(); } +void db_key::loadContainer() +{ + XSqlQuery q; + + db_base::loadContainer(); + FOR_ALL_pki(key, pki_key) + key->setUcount(0); + + SQL_PREPARE(q, "SELECT pkey, COUNT(*) FROM x509super WHERE pkey IS NOT NULL GROUP by pkey"); + q.exec(); + while (q.next()) { + pki_key *key = lookupPki(q.value(0)); + if (!key) { + qDebug() << "Unknown key" << q.value(0).toULongLong(); + continue; + } + key->setUcount(q.value(1).toInt()); + } + MainWindow::dbSqlError(q.lastError()); +} + dbheaderList db_key::getHeaders() { dbheaderList h = db_base::getHeaders(); diff --git a/lib/db_key.h b/lib/db_key.h index e0da818e..86ed58d8 100644 --- a/lib/db_key.h +++ b/lib/db_key.h @@ -34,6 +34,7 @@ class db_key: public db_base pki_base* insert(pki_base *item); void writeAll(); void setOwnPass(QModelIndex idx, enum pki_key::passType); + void loadContainer(); public slots: void newItem(); diff --git a/lib/pki_key.h b/lib/pki_key.h index 6fb201bb..c5ade8f6 100644 --- a/lib/pki_key.h +++ b/lib/pki_key.h @@ -61,6 +61,10 @@ class pki_key: public pki_base int getKeyType() const; bool isPrivKey() const; int getUcount() const; + void setUcount(int c) + { + useCount = c; + } enum passType getOwnPass(void) { return ownPass;