Nattyboi commited on
Commit
2c32b64
·
1 Parent(s): a4cc435

added index

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -490,16 +490,19 @@ def handle_change(change):
490
  # add everybodies points and add it to the leaderboard table
491
  collections = db.list_collection_names()
492
  if "LeaderBoard" not in collections:
493
- print("Collection doesnt exists.")
494
- # loop through points, get userId from points and total points from points table then we
495
- # loop through userId and get the firstName and LastName of each userId lastly
496
- # loop throguh the questionarier using the userId and get the careerPath of each user
497
  users = get_all_users()
498
  for user in users:
499
  points = get_all_simple_points_func(userId=str(user['_id']))
500
  tempDreamJob = get_dream_job(userId=str(user['_id']))
501
  dreamJob = tempDreamJob if type(tempDreamJob)==str else "IncompleteProfile"
 
502
  create_leaderboard_ranking(LeaderBoardRanking(userId=str(user['_id']),firstName=user['first_name'],lastName=user['last_name'],totalpoints=points.totalpoints,lastUpdated=datetime.now(),careerPath=dreamJob,))
 
 
 
 
 
503
  else:
504
  if change['operationType'] == 'insert':
505
  # Extract the full document
 
490
  # add everybodies points and add it to the leaderboard table
491
  collections = db.list_collection_names()
492
  if "LeaderBoard" not in collections:
493
+
 
 
 
494
  users = get_all_users()
495
  for user in users:
496
  points = get_all_simple_points_func(userId=str(user['_id']))
497
  tempDreamJob = get_dream_job(userId=str(user['_id']))
498
  dreamJob = tempDreamJob if type(tempDreamJob)==str else "IncompleteProfile"
499
+
500
  create_leaderboard_ranking(LeaderBoardRanking(userId=str(user['_id']),firstName=user['first_name'],lastName=user['last_name'],totalpoints=points.totalpoints,lastUpdated=datetime.now(),careerPath=dreamJob,))
501
+ leaderBoardcollection = db['LeaderBoard']
502
+ index = leaderBoardcollection.create_index([
503
+ ('lastName', 1),
504
+ ('totalpoints', -1)
505
+ ])
506
  else:
507
  if change['operationType'] == 'insert':
508
  # Extract the full document