LogicGoInfotechSpaces commited on
Commit
9f29203
·
verified ·
1 Parent(s): c7e838b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -76
app.py CHANGED
@@ -317,81 +317,9 @@ async def face_swap_api(
317
  #category_oid = doc["categoryId"] # <-- DO NOT CONVERT TO STRING
318
  subcategory_oid = doc["_id"]
319
 
320
- # ------------------------------------------------------------------
321
- # # MEDIA_CLICKS (ONLY IF user_id PRESENT
322
- # if user_id:
323
- # try:
324
- # user_oid = ObjectId(user_id.strip())
325
- # now = datetime.utcnow()
326
-
327
- # # -------------------------------------------------
328
- # # STEP 1: Ensure root fields exist (NO inc here)
329
- # # -------------------------------------------------
330
- # await media_clicks_col.update_one(
331
- # {"userId": user_oid},
332
- # {
333
- # "$setOnInsert": {
334
- # "userId": user_oid,
335
- # "createdAt": now,
336
- # "ai_edit_complete": 0
337
- # }
338
- # },
339
- # upsert=True
340
- # )
341
-
342
- # # -------------------------------------------------
343
- # # STEP 2: Try updating existing subCategory
344
- # # -------------------------------------------------
345
- # update_result = await media_clicks_col.update_one(
346
- # {
347
- # "userId": user_oid,
348
- # "subCategories.subCategoryId": subcategory_oid
349
- # },
350
- # {
351
- # "$inc": {
352
- # "subCategories.$.click_count": 1,
353
- # "ai_edit_complete": 1
354
- # },
355
- # "$set": {
356
- # "subCategories.$.lastClickedAt": now,
357
- # "ai_edit_last_date": now,
358
- # "updatedAt": now
359
- # }
360
- # }
361
- # )
362
-
363
- # # -------------------------------------------------
364
- # # STEP 3: Push subCategory if missing
365
- # # -------------------------------------------------
366
- # if update_result.matched_count == 0:
367
- # await media_clicks_col.update_one(
368
- # {"userId": user_oid},
369
- # {
370
- # "$inc": {
371
- # "ai_edit_complete": 1
372
- # },
373
- # "$set": {
374
- # "ai_edit_last_date": now,
375
- # "updatedAt": now
376
- # },
377
- # "$push": {
378
- # "subCategories": {
379
- # "subCategoryId": subcategory_oid,
380
- # "click_count": 1,
381
- # "lastClickedAt": now
382
- # }
383
- # }
384
- # }
385
- # )
386
-
387
- # logger.info(
388
- # "[MEDIA_CLICK] user=%s subCategory=%s ai_edit_complete++",
389
- # user_id,
390
- # str(subcategory_oid)
391
- # )
392
-
393
- # except Exception as media_err:
394
- # logger.error(f"MEDIA_CLICK ERROR: {media_err}")
395
  if user_id:
396
  try:
397
  user_oid = ObjectId(user_id.strip())
@@ -467,7 +395,32 @@ async def face_swap_api(
467
  }
468
  }
469
  )
470
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
471
  # -------------------------------------------------
472
  # STEP 3: Try updating existing subCategory
473
  # -------------------------------------------------
 
317
  #category_oid = doc["categoryId"] # <-- DO NOT CONVERT TO STRING
318
  subcategory_oid = doc["_id"]
319
 
320
+ # ------------------------------------------------------------------#
321
+ # # MEDIA_CLICKS (ONLY IF user_id PRESENT)
322
+ # ------------------------------------------------------------------#
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
323
  if user_id:
324
  try:
325
  user_oid = ObjectId(user_id.strip())
 
395
  }
396
  }
397
  )
398
+
399
+ # -------------------------------------------------
400
+ # STEP 2.5: Keep ONLY last 32 days of ai_edit_daily_count
401
+ # -------------------------------------------------
402
+ doc = await media_clicks_col.find_one(
403
+ {"userId": user_oid},
404
+ {"ai_edit_daily_count": 1}
405
+ )
406
+
407
+ daily_entries = doc.get("ai_edit_daily_count", [])
408
+
409
+ if len(daily_entries) > 32:
410
+ # Sort by date ASC (oldest first)
411
+ daily_entries.sort(key=lambda x: x["date"])
412
+
413
+ # Keep last 32
414
+ trimmed_entries = daily_entries[-32:]
415
+
416
+ await media_clicks_col.update_one(
417
+ {"userId": user_oid},
418
+ {
419
+ "$set": {
420
+ "ai_edit_daily_count": trimmed_entries
421
+ }
422
+ }
423
+ )
424
  # -------------------------------------------------
425
  # STEP 3: Try updating existing subCategory
426
  # -------------------------------------------------