Skip to content

Commit 10c010a

Browse files
fix(record_usages): streamline upsert parameter construction and enhance user filtering logic
1 parent 0b0ddaa commit 10c010a

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

app/jobs/record_usages.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -353,14 +353,12 @@ async def record_user_stats_batched(all_node_params: dict, usage_coefficients: d
353353
continue
354354
coeff = usage_coefficients.get(node_id, 1.0)
355355
for p in params:
356-
upsert_params.append(
357-
{
358-
"uid": int(p["uid"]),
359-
"value": int(p["value"] * coeff),
360-
"node_id": node_id,
361-
"created_at": created_at,
362-
}
363-
)
356+
upsert_params.append({
357+
"uid": int(p["uid"]),
358+
"value": int(p["value"] * coeff),
359+
"node_id": node_id,
360+
"created_at": created_at,
361+
})
364362

365363
if not upsert_params:
366364
return
@@ -645,8 +643,10 @@ async def _record_user_usages_impl():
645643
logger.warning("Skipping user usage recording; no matching users found for received stats")
646644
return
647645

648-
# Filter valid users - simple operation, no need to parallelize
649-
valid_users_usage = [usage for usage in users_usage if int(usage["uid"]) in valid_user_ids]
646+
# Filter valid users - only include users with actual non-zero traffic
647+
valid_users_usage = [
648+
usage for usage in users_usage if int(usage["uid"]) in valid_user_ids and usage["value"] > 0
649+
]
650650

651651
# Update User table with concurrency control
652652
if valid_users_usage:

0 commit comments

Comments
 (0)