hivemind-sqlite-database 0.4.0a7__tar.gz → 0.4.1a1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of hivemind-sqlite-database might be problematic. Click here for more details.

Files changed (14) hide show
  1. {hivemind_sqlite_database-0.4.0a7 → hivemind_sqlite_database-0.4.1a1}/PKG-INFO +1 -1
  2. {hivemind_sqlite_database-0.4.0a7 → hivemind_sqlite_database-0.4.1a1}/hivemind_sqlite_database/__init__.py +5 -0
  3. {hivemind_sqlite_database-0.4.0a7 → hivemind_sqlite_database-0.4.1a1}/hivemind_sqlite_database/version.py +2 -2
  4. {hivemind_sqlite_database-0.4.0a7 → hivemind_sqlite_database-0.4.1a1}/hivemind_sqlite_database.egg-info/PKG-INFO +1 -1
  5. {hivemind_sqlite_database-0.4.0a7 → hivemind_sqlite_database-0.4.1a1}/tests/test_sqlitedb.py +20 -0
  6. {hivemind_sqlite_database-0.4.0a7 → hivemind_sqlite_database-0.4.1a1}/LICENSE.md +0 -0
  7. {hivemind_sqlite_database-0.4.0a7 → hivemind_sqlite_database-0.4.1a1}/README.md +0 -0
  8. {hivemind_sqlite_database-0.4.0a7 → hivemind_sqlite_database-0.4.1a1}/hivemind_sqlite_database.egg-info/SOURCES.txt +0 -0
  9. {hivemind_sqlite_database-0.4.0a7 → hivemind_sqlite_database-0.4.1a1}/hivemind_sqlite_database.egg-info/dependency_links.txt +0 -0
  10. {hivemind_sqlite_database-0.4.0a7 → hivemind_sqlite_database-0.4.1a1}/hivemind_sqlite_database.egg-info/entry_points.txt +0 -0
  11. {hivemind_sqlite_database-0.4.0a7 → hivemind_sqlite_database-0.4.1a1}/hivemind_sqlite_database.egg-info/requires.txt +0 -0
  12. {hivemind_sqlite_database-0.4.0a7 → hivemind_sqlite_database-0.4.1a1}/hivemind_sqlite_database.egg-info/top_level.txt +0 -0
  13. {hivemind_sqlite_database-0.4.0a7 → hivemind_sqlite_database-0.4.1a1}/pyproject.toml +0 -0
  14. {hivemind_sqlite_database-0.4.0a7 → hivemind_sqlite_database-0.4.1a1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hivemind-sqlite-database
3
- Version: 0.4.0a7
3
+ Version: 0.4.1a1
4
4
  Summary: sqlite database plugin for hivemind-core
5
5
  Author-email: jarbasAi <jarbasai@mailfence.com>
6
6
  License: Apache-2.0
@@ -92,6 +92,11 @@ class SQLiteDB(AbstractDB):
92
92
  metadata TEXT
93
93
  )
94
94
  """)
95
+ # api_key is looked up on every client connection admission
96
+ # (get_client_by_api_key), so a full table scan there is hot.
97
+ self.conn.execute(
98
+ "CREATE INDEX IF NOT EXISTS idx_clients_api_key ON clients(api_key)"
99
+ )
95
100
  columns = {
96
101
  row["name"]
97
102
  for row in self.conn.execute("PRAGMA table_info(clients)").fetchall()
@@ -1,8 +1,8 @@
1
1
  # START_VERSION_BLOCK
2
2
  VERSION_MAJOR = 0
3
3
  VERSION_MINOR = 4
4
- VERSION_BUILD = 0
5
- VERSION_ALPHA = 7
4
+ VERSION_BUILD = 1
5
+ VERSION_ALPHA = 1
6
6
  # END_VERSION_BLOCK
7
7
 
8
8
  __version__ = f"{VERSION_MAJOR}.{VERSION_MINOR}.{VERSION_BUILD}" + (f"a{VERSION_ALPHA}" if VERSION_ALPHA else "")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hivemind-sqlite-database
3
- Version: 0.4.0a7
3
+ Version: 0.4.1a1
4
4
  Summary: sqlite database plugin for hivemind-core
5
5
  Author-email: jarbasAi <jarbasai@mailfence.com>
6
6
  License: Apache-2.0
@@ -783,6 +783,26 @@ class TestSQLiteDBGetClientByID(unittest.TestCase):
783
783
  self.assertEqual(db.refresh(1).allowed_types, ["y"])
784
784
 
785
785
 
786
+ class TestSQLiteDBApiKeyIndex(unittest.TestCase):
787
+ def test_index_exists_after_init(self):
788
+ db = make_db()
789
+ row = db.conn.execute(
790
+ "SELECT name FROM sqlite_master WHERE type='index' "
791
+ "AND name='idx_clients_api_key'"
792
+ ).fetchone()
793
+ self.assertIsNotNone(row)
794
+
795
+ def test_api_key_lookup_uses_index(self):
796
+ db = make_db()
797
+ plan = db.conn.execute(
798
+ "EXPLAIN QUERY PLAN SELECT * FROM clients WHERE api_key = ?",
799
+ ("k1",),
800
+ ).fetchall()
801
+ detail = " ".join(row["detail"] for row in plan)
802
+ self.assertIn("SEARCH", detail)
803
+ self.assertNotIn("SCAN", detail)
804
+
805
+
786
806
  class TestSQLiteDBSchemaV2RoundTrip(unittest.TestCase):
787
807
  """v2 schema: allowed_types + skill/intent blacklists (in metadata) survive
788
808
  add→search and add→refresh cycles without loss or mutation."""