LogicGoInfotechSpaces commited on
Commit
201770d
Β·
verified Β·
1 Parent(s): ea23782

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -12
app.py CHANGED
@@ -319,12 +319,13 @@ async def face_swap_api(
319
  subcategory_oid = doc["_id"]
320
 
321
  # ------------------------------------------------------------------
 
322
  # MEDIA_CLICKS (ONLY IF user_id PRESENT)
323
  if user_id:
324
  try:
325
  user_oid = ObjectId(user_id.strip())
326
  now = datetime.utcnow()
327
-
328
  # 1) Try updating existing subCategory
329
  update_result = await media_clicks_col.update_one(
330
  {
@@ -332,37 +333,97 @@ async def face_swap_api(
332
  "subCategories.subCategoryId": subcategory_oid
333
  },
334
  {
335
- "$set": {
336
- "updatedAt": now,
337
- "subCategories.$.lastClickedAt": now
338
- },
339
  "$inc": {
340
- "subCategories.$.click_count": 1
 
 
 
 
 
 
341
  }
342
  }
343
  )
344
-
345
- # 2) If no subCategory exists β†’ push new one (or create doc)
346
  if update_result.matched_count == 0:
347
  await media_clicks_col.update_one(
348
  { "userId": user_oid },
349
  {
350
- "$setOnInsert": { "createdAt": now },
351
- "$set": { "updatedAt": now },
 
 
 
 
 
352
  "$push": {
353
  "subCategories": {
354
  "subCategoryId": subcategory_oid,
355
  "click_count": 1,
356
- "lastClickedAt": now
 
 
357
  }
358
  }
359
  },
360
  upsert=True
361
  )
362
-
 
 
 
 
 
 
363
  except Exception as media_err:
364
  logger.error(f"MEDIA_CLICK ERROR: {media_err}")
365
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
366
  # # ------------------------------------------------------------------
367
  # # CASE 2 : target_category_id β†’ DigitalOcean path (unchanged logic)
368
  # # ------------------------------------------------------------------
 
319
  subcategory_oid = doc["_id"]
320
 
321
  # ------------------------------------------------------------------
322
+ # # MEDIA_CLICKS (ONLY IF user_id PRESENT
323
  # MEDIA_CLICKS (ONLY IF user_id PRESENT)
324
  if user_id:
325
  try:
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
  {
 
333
  "subCategories.subCategoryId": subcategory_oid
334
  },
335
  {
 
 
 
 
336
  "$inc": {
337
+ "subCategories.$.click_count": 1,
338
+ "subCategories.$.ai_edit_complete": 1
339
+ },
340
+ "$set": {
341
+ "subCategories.$.lastClickedAt": now,
342
+ "subCategories.$.ai_edit_last_date": now,
343
+ "updatedAt": now
344
  }
345
  }
346
  )
347
+
348
+ # 2) If subCategory does NOT exist β†’ push new entry
349
  if update_result.matched_count == 0:
350
  await media_clicks_col.update_one(
351
  { "userId": user_oid },
352
  {
353
+ "$setOnInsert": {
354
+ "userId": user_oid,
355
+ "createdAt": now
356
+ },
357
+ "$set": {
358
+ "updatedAt": now
359
+ },
360
  "$push": {
361
  "subCategories": {
362
  "subCategoryId": subcategory_oid,
363
  "click_count": 1,
364
+ "lastClickedAt": now,
365
+ "ai_edit_complete": 1,
366
+ "ai_edit_last_date": now
367
  }
368
  }
369
  },
370
  upsert=True
371
  )
372
+
373
+ logger.info(
374
+ "MEDIA_CLICK_SUBCATEGORY | user=%s | subCategory=%s | ai_edit_complete+1",
375
+ user_id,
376
+ str(subcategory_oid)
377
+ )
378
+
379
  except Exception as media_err:
380
  logger.error(f"MEDIA_CLICK ERROR: {media_err}")
381
 
382
+
383
+
384
+ # if user_id:
385
+ # try:
386
+ # user_oid = ObjectId(user_id.strip())
387
+ # now = datetime.utcnow()
388
+
389
+ # # 1) Try updating existing subCategory
390
+ # update_result = await media_clicks_col.update_one(
391
+ # {
392
+ # "userId": user_oid,
393
+ # "subCategories.subCategoryId": subcategory_oid
394
+ # },
395
+ # {
396
+ # "$set": {
397
+ # "updatedAt": now,
398
+ # "subCategories.$.lastClickedAt": now
399
+ # },
400
+ # "$inc": {
401
+ # "subCategories.$.click_count": 1
402
+ # }
403
+ # }
404
+ # )
405
+
406
+ # # 2) If no subCategory exists β†’ push new one (or create doc)
407
+ # if update_result.matched_count == 0:
408
+ # await media_clicks_col.update_one(
409
+ # { "userId": user_oid },
410
+ # {
411
+ # "$setOnInsert": { "createdAt": now },
412
+ # "$set": { "updatedAt": now },
413
+ # "$push": {
414
+ # "subCategories": {
415
+ # "subCategoryId": subcategory_oid,
416
+ # "click_count": 1,
417
+ # "lastClickedAt": now
418
+ # }
419
+ # }
420
+ # },
421
+ # upsert=True
422
+ # )
423
+
424
+ # except Exception as media_err:
425
+ # logger.error(f"MEDIA_CLICK ERROR: {media_err}")
426
+
427
  # # ------------------------------------------------------------------
428
  # # CASE 2 : target_category_id β†’ DigitalOcean path (unchanged logic)
429
  # # ------------------------------------------------------------------