LogicGoInfotechSpaces commited on
Commit
f6241b2
·
verified ·
1 Parent(s): 297e5c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -14
app.py CHANGED
@@ -326,7 +326,24 @@ async def face_swap_api(
326
  user_oid = ObjectId(user_id.strip())
327
  now = datetime.utcnow()
328
 
329
- # 1) Try updating existing subCategory
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
330
  update_result = await media_clicks_col.update_one(
331
  {
332
  "userId": user_oid,
@@ -341,23 +358,17 @@ async def face_swap_api(
341
  "subCategories.$.lastClickedAt": now,
342
  "ai_edit_last_date": now,
343
  "updatedAt": now
344
- },
345
- "$setOnInsert": {
346
- "createdAt": now
347
  }
348
  }
349
  )
350
 
351
- # 2) If no subCategory exists → push new one (or create doc)
 
 
352
  if update_result.matched_count == 0:
353
  await media_clicks_col.update_one(
354
- { "userId": user_oid },
355
  {
356
- "$setOnInsert": {
357
- "userId": user_oid,
358
- "createdAt": now,
359
- "ai_edit_complete": 0 # initialize safely
360
- },
361
  "$inc": {
362
  "ai_edit_complete": 1
363
  },
@@ -372,12 +383,11 @@ async def face_swap_api(
372
  "lastClickedAt": now
373
  }
374
  }
375
- },
376
- upsert=True
377
  )
378
 
379
  logger.info(
380
- "MEDIA_CLICK | user=%s | subCategory=%s | ai_edit_complete++",
381
  user_id,
382
  str(subcategory_oid)
383
  )
@@ -387,6 +397,7 @@ async def face_swap_api(
387
 
388
 
389
 
 
390
 
391
  # if user_id:
392
  # try:
 
326
  user_oid = ObjectId(user_id.strip())
327
  now = datetime.utcnow()
328
 
329
+ # -------------------------------------------------
330
+ # STEP 1: Ensure root fields exist (NO inc here)
331
+ # -------------------------------------------------
332
+ await media_clicks_col.update_one(
333
+ {"userId": user_oid},
334
+ {
335
+ "$setOnInsert": {
336
+ "userId": user_oid,
337
+ "createdAt": now,
338
+ "ai_edit_complete": 0
339
+ }
340
+ },
341
+ upsert=True
342
+ )
343
+
344
+ # -------------------------------------------------
345
+ # STEP 2: Try updating existing subCategory
346
+ # -------------------------------------------------
347
  update_result = await media_clicks_col.update_one(
348
  {
349
  "userId": user_oid,
 
358
  "subCategories.$.lastClickedAt": now,
359
  "ai_edit_last_date": now,
360
  "updatedAt": now
 
 
 
361
  }
362
  }
363
  )
364
 
365
+ # -------------------------------------------------
366
+ # STEP 3: Push subCategory if missing
367
+ # -------------------------------------------------
368
  if update_result.matched_count == 0:
369
  await media_clicks_col.update_one(
370
+ {"userId": user_oid},
371
  {
 
 
 
 
 
372
  "$inc": {
373
  "ai_edit_complete": 1
374
  },
 
383
  "lastClickedAt": now
384
  }
385
  }
386
+ }
 
387
  )
388
 
389
  logger.info(
390
+ "[MEDIA_CLICK] user=%s subCategory=%s ai_edit_complete++",
391
  user_id,
392
  str(subcategory_oid)
393
  )
 
397
 
398
 
399
 
400
+
401
 
402
  # if user_id:
403
  # try: