]> git.mxchange.org Git - quix0rs-apt-p2p.git/blobdiff - apt_p2p_Khashmir/db.py
Start using the new DHT stats module (untested).
[quix0rs-apt-p2p.git] / apt_p2p_Khashmir / db.py
index 47e974cf62122bab33cd4b4a4868a92e873bf822..4ee9cb38068d69978828ca8c328b36d053fe15cc 100644 (file)
@@ -148,6 +148,19 @@ class DB:
         c.execute("DELETE FROM kv WHERE last_refresh < ?", (t, ))
         self.conn.commit()
         
+    def keyStats(self):
+        """Count the total number of keys and values in the database.
+        @rtype: (C{int), C{int})
+        @return: the number of distinct keys and total values in the database
+        """
+        c = self.conn.cursor()
+        c.execute("SELECT COUNT(DISTINCT key) as num_keys, COUNT(value) as num_values FROM kv")
+        keys, values = 0, 0
+        row = c.fetchone()
+        if row:
+            keys, values = row[0], row[1]
+        return keys, values
+
 class TestDB(unittest.TestCase):
     """Tests for the khashmir database."""