Get all papers for a specific push ID Args: push_id: Push ID Returns: Push information with papers list
(push_id: str)
| 1770 | ) -> Optional[Dict[str, Any]]: |
| 1771 | """ |
| 1772 | Return the latest reading-signal profile update for a user. |
| 1773 | |
| 1774 | This is used to reinforce the most recent direct-upload PDF topics when the |
| 1775 | user follows up with a generic phrase like "这类我最近想多看". |
| 1776 | """ |
| 1777 | since_timestamp = (datetime.now() - timedelta(minutes=max(1, int(minutes)))).isoformat(sep=" ") |
| 1778 | |
| 1779 | conn = get_connection() |
| 1780 | cursor = conn.cursor() |
| 1781 | cursor.execute( |
| 1782 | """ |
| 1783 | SELECT id, user_id, push_id, paper_id, action, action_type, category, timestamp, metadata |
| 1784 | FROM behavior_logs |
| 1785 | WHERE user_id = ? |
| 1786 | AND action = 'profile_updated' |
| 1787 | AND action_type = 'reading_signal' |
| 1788 | AND timestamp >= ? |
| 1789 | ORDER BY timestamp DESC, id DESC |
| 1790 | LIMIT 20 |
| 1791 | """, |
| 1792 | (user_id, since_timestamp), |
| 1793 | ) |
| 1794 | rows = cursor.fetchall() |
| 1795 | conn.close() |
| 1796 | |
| 1797 | for row in rows: |
| 1798 | record = dict(row) |
| 1799 | metadata = _load_json_metadata(record.get("metadata")) |
| 1800 | source_type = _normalize_identifier(metadata.get("source_type") or metadata.get("report_source_type")) |
| 1801 | if source_prefix and (not source_type or not source_type.startswith(source_prefix)): |
| 1802 | continue |
| 1803 | |
| 1804 | topics = _deserialize_json_list(metadata.get("signal_topics") or metadata.get("topics")) |
| 1805 | activated_topics = _deserialize_json_list(metadata.get("activated_topics")) |
| 1806 | if not topics: |
| 1807 | continue |
| 1808 | |
| 1809 | record["metadata"] = metadata |
| 1810 | record["topics"] = topics |
| 1811 | record["activated_topics"] = activated_topics |
| 1812 | record["source_type"] = source_type |
| 1813 | record["source_key"] = _normalize_identifier(metadata.get("source_key") or metadata.get("report_source_key")) |
| 1814 | record["signal_strength"] = str(metadata.get("signal_strength") or metadata.get("strength") or "").strip() |
| 1815 | return record |
| 1816 | |
| 1817 | return None |
| 1818 | |
| 1819 | |
| 1820 | def get_push_papers(push_id: str) -> Optional[Dict]: |
| 1821 | """ |
| 1822 | Get all papers for a specific push ID |
| 1823 | |
| 1824 | Args: |
| 1825 | push_id: Push ID |
| 1826 | |
| 1827 | Returns: |
| 1828 | Push information with papers list |
| 1829 | """ |