LogicGoInfotechSpaces commited on
Commit
95ee2de
·
verified ·
1 Parent(s): 1b5d735

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -48
app.py CHANGED
@@ -868,58 +868,58 @@ class Upscale:
868
  im_buf_arr.tofile(save_path)
869
 
870
  def sync_log_media_click(user_id_str: str, category_id_str: str):
871
- """
872
- Synchronously logs a click event to the media_clicks collection.
873
- This function should be run using asyncio.to_thread().
874
- """
875
- if _media_clicks_col is None:
876
- return
877
-
878
- try:
879
- user_oid = ObjectId(user_id_str.strip())
880
- category_oid = ObjectId(category_id_str.strip())
881
- now = datetime.utcnow()
882
-
883
- # 1. Try updating an existing category entry within the user's document
884
- update_result = _media_clicks_col.update_one(
885
- {
886
- "userId": user_oid,
887
- "categories.categoryId": category_oid
888
- },
889
- {
890
- "$set": {
891
- "updatedAt": now,
892
- "categories.$.lastClickedAt": now
893
  },
894
- "$inc": {
895
- "categories.$.click_count": 1
896
- }
897
- }
898
- )
899
-
900
- # 2. If no category entry exists (matched_count == 0) -> push a new one (or create user doc)
901
- if update_result.matched_count == 0:
902
- _media_clicks_col.update_one(
903
- { "userId": user_oid },
904
  {
905
- "$setOnInsert": { "createdAt": now },
906
- "$set": { "updatedAt": now },
907
- "$push": {
908
- "categories": {
909
- "categoryId": category_oid,
910
- "click_count": 1,
911
- "lastClickedAt": now
912
- }
913
  }
914
- },
915
- upsert=True
916
  )
917
-
918
- # logger.info(f"Media click logged for User {user_id_str} on Category {category_id_str}")
919
-
920
- except Exception as media_err:
921
- # logger.error(f"MEDIA_CLICK LOGGING ERROR: {media_err}")
922
- pass # Handle logging error gracefully
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
923
 
924
  class Timer:
925
  def __init__(self):
 
868
  im_buf_arr.tofile(save_path)
869
 
870
  def sync_log_media_click(user_id_str: str, category_id_str: str):
871
+ """
872
+ Synchronously logs a click event to the media_clicks collection.
873
+ This function should be run using asyncio.to_thread().
874
+ """
875
+ if _media_clicks_col is None:
876
+ return
877
+
878
+ try:
879
+ user_oid = ObjectId(user_id_str.strip())
880
+ category_oid = ObjectId(category_id_str.strip())
881
+ now = datetime.utcnow()
882
+
883
+ # 1. Try updating an existing category entry within the user's document
884
+ update_result = _media_clicks_col.update_one(
885
+ {
886
+ "userId": user_oid,
887
+ "categories.categoryId": category_oid
 
 
 
 
 
888
  },
 
 
 
 
 
 
 
 
 
 
889
  {
890
+ "$set": {
891
+ "updatedAt": now,
892
+ "categories.$.lastClickedAt": now
893
+ },
894
+ "$inc": {
895
+ "categories.$.click_count": 1
 
 
896
  }
897
+ }
 
898
  )
899
+
900
+ # 2. If no category entry exists (matched_count == 0) -> push a new one (or create user doc)
901
+ if update_result.matched_count == 0:
902
+ _media_clicks_col.update_one(
903
+ { "userId": user_oid },
904
+ {
905
+ "$setOnInsert": { "createdAt": now },
906
+ "$set": { "updatedAt": now },
907
+ "$push": {
908
+ "categories": {
909
+ "categoryId": category_oid,
910
+ "click_count": 1,
911
+ "lastClickedAt": now
912
+ }
913
+ }
914
+ },
915
+ upsert=True
916
+ )
917
+
918
+ # logger.info(f"Media click logged for User {user_id_str} on Category {category_id_str}")
919
+
920
+ except Exception as media_err:
921
+ # logger.error(f"MEDIA_CLICK LOGGING ERROR: {media_err}")
922
+ pass # Handle logging error gracefully
923
 
924
  class Timer:
925
  def __init__(self):