this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feeds/rapidfire.py: move DB to /dev/shm, commit after each post

+15 -16
+15 -16
feeds/rapidfire.py
··· 6 6 FEED_URI = 'at://did:plc:4nsduwlpivpuur4mqkbfvm6a/app.bsky.feed.generator/rapidfire' 7 7 8 8 def __init__(self): 9 - self.checkpoint = 0 10 - self.db_cnx = sqlite3.connect('db/rapidfire.db') 9 + self.db_cnx = sqlite3.connect('/dev/shm/feedgens/rapidfire.db') 11 10 with self.db_cnx: 12 - self.db_cnx.executescript(""" 13 - pragma journal_mode = WAL; 14 - pragma synchronous = off; 15 - create table if not exists posts (uri text, create_ts timestamp); 16 - create index if not exists create_ts_idx on posts(create_ts); 17 - """) 11 + self.db_cnx.executescript( 12 + "pragma journal_mode = WAL;" 13 + "pragma synchronous = OFF;" 14 + "create table if not exists posts (uri text, create_ts timestamp);" 15 + "create index if not exists create_ts_idx on posts(create_ts);" 16 + ) 18 17 19 18 def process(self, commit): 20 19 op = commit['op'] ··· 38 37 repo = commit['repo'] 39 38 path = op['path'] 40 39 post_uri = f'at://{repo}/{path}' 41 - self.db_cnx.execute( 42 - 'insert into posts (uri, create_ts) values (:uri, :ts)', 43 - dict(uri=post_uri, ts=ts) 44 - ) 45 40 46 - self.checkpoint += 1 47 - if self.checkpoint % 10 == 0: 48 - self.db_cnx.execute("delete from posts where strftime('%s', create_ts) < strftime('%s', 'now', '-1 hour')") 49 - self.db_cnx.commit() 41 + with self.db_cnx: 42 + self.db_cnx.execute( 43 + 'insert into posts (uri, create_ts) values (:uri, :ts)', 44 + dict(uri=post_uri, ts=ts) 45 + ) 46 + self.db_cnx.execute( 47 + "delete from posts where strftime('%s', create_ts) < strftime('%s', 'now', '-15 minutes')" 48 + ) 50 49 51 50 def serve(self, limit, offset): 52 51 cur = self.db_cnx.execute(