this repo has no description
0
fork

Configure Feed

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

feeds/rapidfire.py: convert to commit_changes and use transactions

+13 -8
+13 -8
feeds/rapidfire.py
··· 12 12 FEED_URI = 'at://did:plc:4nsduwlpivpuur4mqkbfvm6a/app.bsky.feed.generator/rapidfire' 13 13 14 14 def __init__(self): 15 + super().__init__() 16 + 15 17 db_fname = '' 16 18 if os.path.isdir('/dev/shm/'): 17 19 os.makedirs('/dev/shm/feedgens/', exist_ok=True) ··· 54 56 post_uri = f'at://{repo}/{path}' 55 57 ts = self.safe_timestamp(record['createdAt']).timestamp() 56 58 59 + self.transaction_begin(self.db_cnx) 60 + 57 61 langs = record.get('langs') or [''] 58 62 for lang in langs: 59 63 self.db_cnx.execute( ··· 61 65 dict(uri=post_uri, ts=ts, lang=lang) 62 66 ) 63 67 64 - def run_tasks_minute(self): 65 - self.logger.debug('running minute tasks') 68 + def delete_old_posts(self): 69 + self.db_cnx.execute( 70 + "delete from posts where create_ts < unixepoch('now', '-15 minutes')" 71 + ) 66 72 67 - with self.db_cnx: 68 - self.db_cnx.execute( 69 - "delete from posts where create_ts < unixepoch('now', '-15 minutes')" 70 - ) 71 - 72 - self.db_cnx.pragma('wal_checkpoint(TRUNCATE)') 73 + def commit_changes(self): 74 + self.logger.debug('comitting changes') 75 + self.delete_old_posts() 76 + self.transaction_commit(self.db_cnx) 77 + self.wal_checkpoint(self.db_cnx, 'RESTART') 73 78 74 79 def serve_feed(self, limit, offset, langs): 75 80 if '*' in langs: