Skip to content

feat(papers): count and show views and downloads of each paper - #570

Open
Dx-Alz-xD wants to merge 2 commits into
CodeChefVIT:stagingfrom
Dx-Alz-xD:krish/paper-view-download-counts
Open

Dx-Alz-xD wants to merge 2 commits into
CodeChefVIT:stagingfrom
Dx-Alz-xD:krish/paper-view-download-counts

Conversation

@Dx-Alz-xD

Copy link
Copy Markdown
Contributor

📌 Purpose

Show how many times each paper was viewed and downloaded, as asked in #551. This covers the counters; likes and comments need decisions on accounts and moderation first.


Corresponding issue: part of #551


🖼️ Showcase

image image

🔧 Changes

  • views and downloads on each paper (default 0)
  • POST /api/paper-counts with { kind: "view" | "download", paperIds } (up to 100, so a zip is one request); it returns the updated counts
  • One visitor counts once an hour per paper and kind (Upstash), so refreshing doesn't inflate the numbers
  • A view counts when the paper page or the card preview opens; a download counts only when it actually worked, from the card, the viewer or the zip
  • Counts show on cards and under the paper title, and update right after a view or download

➕ Additional Notes

  • The catalogue list can lag up to a minute behind, since /api/papers is cached for 60 seconds
  • Likes and comments are left for a separate discussion

@Rithish-2914

Copy link
Copy Markdown
Contributor

Hi @Dx-Alz-xD nice work on this! It now conflicts with #574 (the repeated-download guard) in Card.tsx and newPdfViewer.tsx. Could you rebase and keep the guard, with the count call inside the try? Also, it might be worth adding /api/paper-counts to the middleware rate limits, since it shares Upstash with uploads, and adding an anonymous visitor ID to the dedupe key so campus WiFi users sharing one IP still get counted. Thanks!

each paper now stores how often it was viewed and downloaded. opening
the paper page or the card preview counts a view, and a download that
worked counts a download, from the card, the viewer or the zip. one
visitor counts once an hour per paper, and the counts show on the cards
and under the paper title
… one ip

/api/paper-counts now goes through the middleware like the other routes
that use upstash, at 120 requests a minute per ip

the browser keeps a random visitor id in localStorage and sends it with
each count, so people on the same campus wifi are counted separately
instead of as one ip. each visitor counts once an hour per paper, and one
ip can add at most 50 views or downloads of a paper an hour, so made up
visitor ids cannot inflate a count. a request without a visitor id is
counted once an hour per ip, as before
@Dx-Alz-xD
Dx-Alz-xD force-pushed the krish/paper-view-download-counts branch from 97b35d0 to c8dff8d Compare December 1, 2026 14:14
@Dx-Alz-xD

Copy link
Copy Markdown
Contributor Author

rebased on staging and kept the #574 guard, with the count call inside its try (the card, the viewer and download all). also in c8dff8d:

/api/paper-counts goes through the middleware now, at 120 requests a minute per ip
the browser keeps a random visitor id in localStorage and sends it with each count, so people behind one campus ip are counted separately. each visitor counts once an hour per paper, and one ip can add at most 50 per paper an hour, so made up ids can't inflate a count. requests without an id are still counted once an hour per ip
both limits are one-line changes if youd
like different numbers

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants