MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / get_recent_selected_papers

Function get_recent_selected_papers

skills/storage-helper/scripts/db_ops.py:1593–1664  ·  view source on GitHub ↗

Return recent selected papers with paper data and selected timestamp. Args: user_id: User ID limit: Max number of selected papers to fetch days: Max lookback window in days before_timestamp: Optional upper-bound timestamp (exclusive) Returns: Mo

(
    user_id: str,
    limit: int = 30,
    days: int = 60,
    before_timestamp: Optional[str] = None,
)

Source from the content-addressed store, hash-verified

1591
1592
1593def get_recent_selected_papers(
1594 user_id: str,
1595 limit: int = 30,
1596 days: int = 60,
1597 before_timestamp: Optional[str] = None,
1598) -> List[Dict[str, Any]]:
1599 """
1600 Return recent selected papers with paper data and selected timestamp.
1601
1602 Args:
1603 user_id: User ID
1604 limit: Max number of selected papers to fetch
1605 days: Max lookback window in days
1606 before_timestamp: Optional upper-bound timestamp (exclusive)
1607
1608 Returns:
1609 Most recent selected papers ordered from old to new.
1610 """
1611 normalized_limit = max(1, int(limit))
1612 normalized_days = max(1, int(days))
1613 since_timestamp = (datetime.now() - timedelta(days=normalized_days)).isoformat(sep=" ")
1614
1615 conn = get_connection()
1616 cursor = conn.cursor()
1617
1618 sql = """
1619 SELECT p.*,
1620 bl.id AS behavior_log_id,
1621 bl.timestamp AS selected_at,
1622 bl.metadata AS selected_metadata,
1623 push_bl.metadata AS push_metadata
1624 FROM behavior_logs bl
1625 JOIN papers p ON p.id = bl.paper_id
1626 LEFT JOIN behavior_logs push_bl
1627 ON push_bl.user_id = bl.user_id
1628 AND push_bl.push_id = bl.push_id
1629 AND push_bl.paper_id = bl.paper_id
1630 AND push_bl.action = 'pushed'
1631 WHERE bl.user_id = ?
1632 AND bl.action = 'selected'
1633 AND bl.action_type = 'selected'
1634 AND bl.timestamp >= ?
1635 """
1636 params: List[Any] = [user_id, since_timestamp]
1637
1638 if before_timestamp:
1639 sql += " AND bl.timestamp < ?"
1640 params.append(before_timestamp)
1641
1642 sql += """
1643 ORDER BY bl.timestamp DESC, bl.id DESC
1644 LIMIT ?
1645 """
1646 params.append(normalized_limit)
1647
1648 cursor.execute(sql, params)
1649 rows = cursor.fetchall()
1650 conn.close()

Callers 1

process_feedbackFunction · 0.85

Calls 8

_build_paper_dictFunction · 0.85
nowMethod · 0.80
cursorMethod · 0.80
getMethod · 0.80
get_connectionFunction · 0.70
executeMethod · 0.45
fetchallMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected