Conversation
Dedupe catalog HTML opens per rs_papers_visitor cookie (12h window) so LAN users behind one public IP stay distinct, refreshes do not spam-increment, and X-Real-IP / X-Forwarded-For are recorded for ops only. Skip obvious bots and prefetch; persist seen ids in visit-stats.json. Co-authored-by: Daniel <znsoft@163.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The catalog visit counter no longer treats every HTML refresh as a new visit, and it does not key uniqueness by client IP (which would collapse everyone behind one office NAT /
X-Forwarded-For).Current code on this line was incrementing on every
GET /paperswith no visitor key (IP was never used). The bug to fix was refresh/bot spam plus the wrong fix of keying by IP. Unique identity is now a first-party cookie.Counting rules
GET /papersHTML only (the catalog page). HEAD,/papers/apipolls, and PDF downloads do not.rs_papers_visitor(HttpOnly,Path=/,SameSite=Lax, 1 year;Secureon HTTPS /X-Forwarded-Proto). Minted on first catalog open.Purpose/Sec-Purpose/X-Moz) are skipped.X-Real-IP(preferred; nginx overwrites it), else rightmostX-Forwarded-Forhop (nginx appends$remote_addr), elseRemoteAddr. Leftmost XFF is ignored so clients cannot spoof the logged IP. Stored aslast_iponvisit-stats.jsonand printed on increment; never used as the visitor key.$PAPERS_DIR/visit-stats.json(already gitignored) keepstotalplus recent cookie→timestamp entries, pruned after the window. Legacy{total}files still load.GET /papers/apinow sendsCache-Control: no-storeso the UI does not freeze a stale count.papers()init is mutexed so concurrent first hits share one counter.Stacked on
cursor/papers-google-translate-f7ae.Test plan
go test ./internal/api/ -count=1 -run 'Visit|RequestClientIP|IsBotVisit|PapersPageVisit'X-Real-IP/ rightmostX-Forwarded-Forrecorded; spoofed leftmost XFF is not/paperssets cookie;/papers/apiexposesvisitswithno-store; HEAD does not bumpgo test ./internal/api/ -count=1(one earlier./...run hit a pre-existingTestHFDailyReuseTranslateAndReviewRoutesTempDir cleanup flake; isolated re-run and fullinternal/apipass)X-Real-IP/ shared XFF → 2; refresh and curl/HEAD/API → still 2;last_ipis the real client, not spoofed leftmost XFF/papersshows 3 visits (after those two clients + this browser); refresh stays 3;/papers/api"visits": 3