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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -73
app.py CHANGED
@@ -320,72 +320,12 @@ async def face_swap_api(
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
- {
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,37 +333,97 @@ 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,
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
  # # ------------------------------------------------------------------
 
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
  # # ------------------------------------------------------------------