1
Fork 0
mirror of https://github.com/thegeneralist01/archivr synced 2026-12-04 18:56:44 +01:00
archivr/vendor/twitter
TheGeneralist 8973a514cc perf(twitter): optimize tweet and thread archiving pipeline
Accelerates tweet and thread archiving times by up to 11x on live
Twitter and reduces processing overhead across Python and Rust:

- In-memory GraphQL thread caching: parse and cache all tweets returned
  in TweetDetail conversation timeline (threaded_conversation_with_injections_v2),
  resolving parent/replied-to tweets in threads immediately without
  redundant network round-trips.
- Proactive rate limiting: replace blind 2.0s post-save sleep with proactive
  throttling prior to outgoing HTTP requests, eliminating trailing sleep on
  single tweets and intermediate sleep for cached thread tweets.
- HTTP keep-alive connection reuse: reuse scraper session for downloading
  media assets and avatars, avoiding fresh TCP/TLS handshakes per asset.
- Avatar & media deduplication: skip avatar download if target file already
  exists on disk.
- Lightweight client startup: introduce SimpleTwitterScraper using direct
  httpx.Client with authenticated headers and lazy twitter.scraper fallback,
  eliminating ~30ms of module imports at startup.
- Fast JSON I/O: use orjson for binary JSON parsing and indented serialization.
- Rust database batching: wrap entry creation, blob upserts, artifact
  registration, and run completion in a single SQLite transaction, reducing
  fsyncs from ~19 down to 1.
- In-memory blob caching: cache blob records across tweet artifacts to
  avoid repeated filesystem metadata stats and duplicate upserts.
- Single-pass staging: rewrite and move staged JSON files directly to
  raw_tweets/ in a single pass without intermediate staging writes.
- Zero-copy metadata deserialization: use borrowed TweetJsonMetadata struct
  to extract title/metadata without dynamic Value heap allocations.
- Regex fast paths: add substring gates before compiling/iterating asset regexes.
2026-10-21 20:28:53 +02:00
..
scripts chore: add isolate_cookies script 2026-04-03 15:42:20 +02:00
scrape_user_tweet_contents.py perf(twitter): optimize tweet and thread archiving pipeline 2026-10-21 20:28:53 +02:00