LogicGoInfotechSpaces commited on
Commit
0a0439b
·
verified ·
1 Parent(s): 6f01ae6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -18
app.py CHANGED
@@ -217,29 +217,53 @@ async def generate(
217
  # If category or user does not exist
218
  if update_res.matched_count == 0:
219
  media_clicks_col.update_one(
220
- {"userId": user_oid},
221
  {
222
- "$setOnInsert": {
223
- "createdAt": now,
224
- "ai_edit_complete": 0
225
- },
226
- "$set": {
227
- "updatedAt": now,
228
- "ai_edit_last_date": now
229
- },
230
- "$inc": {
231
- "ai_edit_complete": 1
232
- },
233
- "$push": {
234
- "categories": {
235
- "categoryId": category_oid,
236
- "click_count": 1,
237
- "lastClickedAt": now
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
  }
239
  }
240
- },
241
  upsert=True
242
  )
 
243
 
244
  except Exception as e:
245
  print("CATEGORY_LOG_ERROR:", e)
 
217
  # If category or user does not exist
218
  if update_res.matched_count == 0:
219
  media_clicks_col.update_one(
 
220
  {
221
+ "userId": user_oid,
222
+ "categories.categoryId": category_oid
223
+ },
224
+ [
225
+ {
226
+ "$set": {
227
+ "updatedAt": now,
228
+ "ai_edit_last_date": now,
229
+ "ai_edit_complete": {
230
+ "$add": [
231
+ { "$ifNull": ["$ai_edit_complete", 0] },
232
+ 1
233
+ ]
234
+ },
235
+ "categories": {
236
+ "$map": {
237
+ "input": "$categories",
238
+ "as": "cat",
239
+ "in": {
240
+ "$cond": [
241
+ { "$eq": ["$$cat.categoryId", category_oid] },
242
+ {
243
+ "$mergeObjects": [
244
+ "$$cat",
245
+ {
246
+ "click_count": {
247
+ "$add": [
248
+ { "$ifNull": ["$$cat.click_count", 0] },
249
+ 1
250
+ ]
251
+ },
252
+ "lastClickedAt": now
253
+ }
254
+ ]
255
+ },
256
+ "$$cat"
257
+ ]
258
+ }
259
+ }
260
+ }
261
  }
262
  }
263
+ ],
264
  upsert=True
265
  )
266
+
267
 
268
  except Exception as e:
269
  print("CATEGORY_LOG_ERROR:", e)