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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -69
app.py CHANGED
@@ -321,71 +321,11 @@ async def face_swap_api(
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
- # {
332
- # "userId": user_oid,
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
  {
@@ -393,23 +333,38 @@ async def face_swap_api(
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,
@@ -420,10 +375,62 @@ async def face_swap_api(
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
  # # ------------------------------------------------------------------
 
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
+ "ai_edit_complete": 1
339
+ },
340
  "$set": {
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
+ },
364
+ "$set": {
365
+ "ai_edit_last_date": now,
366
+ "updatedAt": now
367
+ },
368
  "$push": {
369
  "subCategories": {
370
  "subCategoryId": subcategory_oid,
 
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
+ )
384
+
385
  except Exception as media_err:
386
  logger.error(f"MEDIA_CLICK ERROR: {media_err}")
387
 
388
+
389
+
390
+
391
+ # if user_id:
392
+ # try:
393
+ # user_oid = ObjectId(user_id.strip())
394
+ # now = datetime.utcnow()
395
+
396
+ # # 1) Try updating existing subCategory
397
+ # update_result = await media_clicks_col.update_one(
398
+ # {
399
+ # "userId": user_oid,
400
+ # "subCategories.subCategoryId": subcategory_oid
401
+ # },
402
+ # {
403
+ # "$set": {
404
+ # "updatedAt": now,
405
+ # "subCategories.$.lastClickedAt": now
406
+ # },
407
+ # "$inc": {
408
+ # "subCategories.$.click_count": 1
409
+ # }
410
+ # }
411
+ # )
412
+
413
+ # # 2) If no subCategory exists β†’ push new one (or create doc)
414
+ # if update_result.matched_count == 0:
415
+ # await media_clicks_col.update_one(
416
+ # { "userId": user_oid },
417
+ # {
418
+ # "$setOnInsert": { "createdAt": now },
419
+ # "$set": { "updatedAt": now },
420
+ # "$push": {
421
+ # "subCategories": {
422
+ # "subCategoryId": subcategory_oid,
423
+ # "click_count": 1,
424
+ # "lastClickedAt": now
425
+ # }
426
+ # }
427
+ # },
428
+ # upsert=True
429
+ # )
430
+
431
+ # except Exception as media_err:
432
+ # logger.error(f"MEDIA_CLICK ERROR: {media_err}")
433
+
434
  # # ------------------------------------------------------------------
435
  # # CASE 2 : target_category_id β†’ DigitalOcean path (unchanged logic)
436
  # # ------------------------------------------------------------------