···
···
FEED_URI = 'at://did:plc:4nsduwlpivpuur4mqkbfvm6a/app.bsky.feed.generator/popular'
if os.path.isdir('/dev/shm/'):
os.makedirs('/dev/shm/feedgens/', exist_ok=True)
14
-
self.db_cnx = sqlite3.connect('/dev/shm/feedgens/popular.db')
15
+
db_fname = '/dev/shm/feedgens/popular.db'
16
-
self.db_cnx = sqlite3.connect('db/popular.db')
17
+
db_fname = 'db/popular.db'
18
-
self.db_cnx.create_function('exp', 1, math.exp)
19
+
self.db_cnx = apsw.Connection(db_fname)
20
+
self.db_cnx.pragma('journal_mode', 'WAL')
21
+
self.db_cnx.pragma('synchronous', 'OFF')
22
+
self.db_cnx.pragma('wal_autocheckpoint', '0')
20
-
self.db_cnx.executescript(
21
-
"pragma journal_mode = WAL;"
22
-
"pragma synchronous = OFF;"
23
-
"pragma wal_autocheckpoint = 0;"
24
-
"create table if not exists posts (uri text, create_ts timestamp, update_ts timestamp, temperature int);"
25
-
"create unique index if not exists uri_idx on posts(uri);"
28
-
self.cleanup_checkpoint = 0
25
+
self.db_cnx.execute("""
26
+
create table if not exists posts (uri text, create_ts timestamp, update_ts timestamp, temperature int);
27
+
create unique index if not exists uri_idx on posts(uri);
def process_commit(self, commit):
···
"on conflict (uri) do update set temperature = temperature + 1, update_ts = :ts"
), dict(uri=like_subject_uri, ts=ts))
49
-
self.cleanup_checkpoint += 1
50
-
if self.cleanup_checkpoint % 1000 == 0:
51
-
sys.stdout.write('popular: running cleanup checkpoint\n')
49
+
def run_tasks_minute(self):
50
+
sys.stdout.write('popular: running minute tasks\n')
55
-
self.db_cnx.execute(
56
-
"delete from posts where temperature * exp( -1 * ( ( strftime( '%s', 'now' ) - strftime( '%s', create_ts ) ) / 1800.0 ) ) < 1.0 and strftime( '%s', create_ts ) < strftime( '%s', 'now', '-15 minutes' )"
60
-
"pragma wal_checkpoint(TRUNCATE)"
55
+
"delete from posts where temperature * exp( -1 * ( ( strftime( '%s', 'now' ) - strftime( '%s', create_ts ) ) / 1800.0 ) ) < 1.0 and strftime( '%s', create_ts ) < strftime( '%s', 'now', '-15 minutes' )"
58
+
self.db_cnx.pragma('wal_checkpoint(TRUNCATE)')
def serve_feed(self, limit, offset, langs):
cur = self.db_cnx.execute((