Browse Source

Explicitly open the sqlite db in read-only mode

Chris Adams 5 years ago
parent
commit
f0da8c6d1f
1 changed files with 8 additions and 1 deletions
  1. 8 1
      only_show_green_results.py

+ 8 - 1
only_show_green_results.py

@@ -64,7 +64,14 @@ class GreenCheck:
 
 
     def check_in_db(self, domain=None):
     def check_in_db(self, domain=None):
 
 
-        with sqlite3.connect(database_name) as con:
+        # we basically treat the the sqlite database like an immutable,
+        # read-only datastructure. This allows multiple concurrent
+        # connections as no state is ever being changed - only read with SELECT
+        #  https://docs.python.org/3.8/library/sqlite3.html#//apple_ref/Function/sqlite3.connect
+        # https://sqlite.org/lockingv3.html
+        with sqlite3.connect(
+                f"file:{database_name}?mode=ro", uri=True, check_same_thread=False
+            ) as con:
             cur = con.cursor()
             cur = con.cursor()
             cur.execute("SELECT green FROM green_presenting WHERE url=? LIMIT 1",
             cur.execute("SELECT green FROM green_presenting WHERE url=? LIMIT 1",
                 [domain]
                 [domain]