this repo has no description
0
fork

Configure Feed

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

feeds/popular.py: every 1k likes, delete cool stuff older than 15m

+8 -3
+8 -3
feeds/popular.py
··· 20 20 "create unique index if not exists uri_idx on posts(uri);" 21 21 ) 22 22 23 + self.cleanup_checkpoint = 0 24 + 23 25 def process(self, commit): 24 26 op = commit['op'] 25 27 if op['action'] != 'create': ··· 39 41 "on conflict (uri) do update set temperature = temperature + 1, update_ts = :ts" 40 42 ), dict(uri=like_subject_uri, ts=ts)) 41 43 42 - self.db_cnx.execute( 43 - "delete from posts where temperature = 1 and strftime('%s', create_ts) < strftime('%s', 'now', '-15 minutes')" 44 - ) 44 + self.cleanup_checkpoint += 1 45 + if self.cleanup_checkpoint % 1000 == 0: 46 + with self.db_cnx: 47 + self.db_cnx.execute( 48 + "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' )" 49 + ) 45 50 46 51 def serve(self, limit, offset, langs): 47 52 cur = self.db_cnx.execute((