File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22import secrets
33import psycopg2
44import requests
5+ import random
6+ import time
57
68REACTIVE_SERVICE_URL = "http://reactive_cache:8081/v1"
79
@@ -250,3 +252,24 @@ def deupvote_post(post_id):
250252@app .get ("/healthcheck" )
251253def healthcheck ():
252254 return "ok" , 200
255+
256+
257+ @app .post ("/simulate_activity" )
258+ def simulate_activity ():
259+ with get_db () as db :
260+ with db .cursor () as cur :
261+ cur .execute ("SELECT id FROM posts" )
262+ post_ids = [x [0 ] for x in cur .fetchall ()]
263+
264+ for i in range (1000 ):
265+ post_id = random .choice (post_ids )
266+ for j in range (random .randrange (20 )):
267+ user_id = random .randint (0 , 1000 )
268+ cur .execute (
269+ "INSERT INTO upvotes(user_id, post_id) VALUES (%s, %s)" ,
270+ (user_id , post_id ),
271+ )
272+ db .commit ()
273+ time .sleep (1 )
274+
275+ return "ok" , 200
Original file line number Diff line number Diff line change @@ -203,6 +203,14 @@ function Feed(props: { posts: Post[]; session: Session | null }) {
203203 ) ;
204204 }
205205
206+ function simulateActivity ( ) {
207+ void fetch ( "/api/simulate_activity" , { method : "POST" } ) . catch (
208+ ( err : unknown ) => {
209+ console . error ( err ) ;
210+ } ,
211+ ) ;
212+ }
213+
206214 return (
207215 < >
208216 < Header session = { session } />
@@ -233,6 +241,14 @@ function Feed(props: { posts: Post[]; session: Session | null }) {
233241 ) ) }
234242 </ ol >
235243 </ div >
244+ < button
245+ onClick = { ( e ) => {
246+ e . preventDefault ( ) ;
247+ simulateActivity ( ) ;
248+ } }
249+ >
250+ Simulate activity
251+ </ button >
236252 </ >
237253 ) ;
238254}
You can’t perform that action at this time.
0 commit comments