Get the latest real push for a user on a specific local date. Args: user_id: User ID target_date: YYYY-MM-DD date string Returns: Push information with papers list, or None when no push exists that day
(user_id: str, target_date: str)
| 1369 | |
| 1370 | |
| 1371 | def get_push_for_date(user_id: str, target_date: str) -> Optional[Dict]: |
| 1372 | """ |
| 1373 | Get the latest real push for a user on a specific local date. |
| 1374 | |
| 1375 | Args: |
| 1376 | user_id: User ID |
| 1377 | target_date: YYYY-MM-DD date string |
| 1378 | |
| 1379 | Returns: |
| 1380 | Push information with papers list, or None when no push exists that day |
| 1381 | """ |
| 1382 | conn = get_connection() |
| 1383 | cursor = conn.cursor() |
| 1384 | |
| 1385 | cursor.execute( |
| 1386 | """ |
| 1387 | SELECT push_id, MAX(timestamp) as timestamp |
| 1388 | FROM behavior_logs |
| 1389 | WHERE user_id = ? |
| 1390 | AND action IN ('pushed', 'push_empty') |
| 1391 | AND date(timestamp) = ? |
| 1392 | GROUP BY push_id |
| 1393 | ORDER BY timestamp DESC, push_id DESC |
| 1394 | LIMIT 1 |
| 1395 | """, |
| 1396 | (user_id, target_date), |
| 1397 | ) |
| 1398 | |
| 1399 | row = cursor.fetchone() |
| 1400 | if not row: |
| 1401 | conn.close() |
| 1402 | return None |
| 1403 | |
| 1404 | push_id = row["push_id"] |
| 1405 | push_time = row["timestamp"] |
| 1406 | |
| 1407 | cursor.execute( |
| 1408 | """ |
| 1409 | SELECT p.*, bl.id as behavior_log_id, bl.metadata as bl_metadata FROM papers p |
| 1410 | JOIN behavior_logs bl ON p.id = bl.paper_id |
| 1411 | WHERE bl.user_id = ? AND bl.push_id = ? AND bl.action = 'pushed' |
| 1412 | ORDER BY bl.id ASC |
| 1413 | """, |
| 1414 | (user_id, push_id), |
| 1415 | ) |
| 1416 | |
| 1417 | papers = [_build_paper_dict(row, metadata_key="bl_metadata") for row in cursor.fetchall()] |
| 1418 | papers.sort(key=lambda paper: (paper.get("rank", 10**9), paper.get("behavior_log_id", 10**9))) |
| 1419 | |
| 1420 | cursor.execute( |
| 1421 | """ |
| 1422 | SELECT metadata |
| 1423 | FROM behavior_logs |
| 1424 | WHERE user_id = ? |
| 1425 | AND push_id = ? |
| 1426 | AND action = 'push_empty' |
| 1427 | ORDER BY id DESC |
| 1428 | LIMIT 1 |
nothing calls this directly
no test coverage detected