close
Skip to content

Comment out broken Unique Visitors chart (#12823) - #12831

Merged
mekarpeles merged 6 commits into
internetarchive:masterfrom
Sadashii:12823/fix/hide-unique-visitors
Jul 20, 2026
Merged

Comment out broken Unique Visitors chart (#12823)#12831
mekarpeles merged 6 commits into
internetarchive:masterfrom
Sadashii:12823/fix/hide-unique-visitors

Conversation

@Sadashii

@Sadashii Sadashii commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

Closes #12823

Dynamically hides the Unique Visitors stats charts on the homepage and the admin dashboard when visitor counts data is not available (such as when the upstream archive.org Graphite pipeline is down).

Technical

  • Wrapped the Unique Visitors chart and JSON embed script in openlibrary/templates/home/stats.html and on the admin stats page openlibrary/templates/admin/index.html with a $if stats["visitors"].get_summary(28): template conditional.
  • Added a clarifying comment note above the conditional blocks: $# Conditional check since the graphite source is currently unreliable, hiding the stat when it returns nothing.
  • Added a timeout=5 parameter to the Graphite request in openlibrary/core/admin.py to prevent hangs when the Graphite server is down.

Testing

Verify style checks:

pre-commit run --files openlibrary/core/admin.py openlibrary/templates/home/stats.html openlibrary/templates/admin/index.html

Screenshot

With valid response,
image

With missing/invalid response,
image


Follow-up (Ada, on behalf of Mek): narrowed the diff + fixed a tooltip bug

Mek's review asked for a smaller, more surgical diff than the one above — see this thread for the full plan. Commit 06a61c702 (pushed on top of the commits above, nothing rewritten/rebased):

  • Reverted scope creep: the original diff removed the .chartShow wrapper div and its CSS rule from all five charts (visitors/members/edits/lists/ebooks) in openlibrary/templates/home/stats.html / static/css/components/home.css, even though only the visitors chart needed conditional rendering. Restored members/edits/lists/ebooks to master's original wrapper structure — they're unconditional, unchanged in behavior.
  • Kept the narrow $if stats["visitors"].get_summary(28): gate around the visitors chart's markup and its graph-json-visitors-graph script tag (homepage) — confirmed the admin page's equivalent gate was already scoped correctly, no change needed there.
  • Kept timeout=5 on the Graphite request in openlibrary/core/admin.py — reasonable, in scope.
  • Moved the pre-existing inline style="width:150px;height:60px;" on each #{id}-graph div into a shared .chart-graph rule in static/css/components/home.css.
  • Fixed a tooltip stacking bug found while in this code: the 5 homepage sparkline tooltips (#chartLabelA, plot_tooltip_graph() in openlibrary/plugins/openlibrary/js/graphs/plot.js) rendered behind the chart because they were missing z-index, unlike the equivalent tooltip in loadEditionsGraph() in the same file (which already sets z-index: 100). Root cause confirmed in a real browser: <main> has position: relative; z-index: 1, which establishes a stacking context that sits above any z-index:auto sibling appended later to <body>, regardless of DOM order — explains why the tooltip (appended last, no z-index) rendered underneath. Setting z-index: 100 (mirroring loadEditionsGraph's existing tooltip) fixes it.

Diff after the follow-up commit is now just 4 files / ~26 insertions, ~15 deletions net:

openlibrary/core/admin.py                          |  5 +++--
openlibrary/plugins/openlibrary/js/graphs/plot.js  |  3 ++-
openlibrary/templates/home/stats.html              | 22 ++++++++++++----------
static/css/components/home.css                     |  6 ++++++

(openlibrary/templates/admin/index.html needed no changes — already scoped correctly.)

How it was tested

  • Automated: full make test (Python + JS unit + i18n) green; targeted pytest openlibrary/plugins/openlibrary/tests/test_home.py openlibrary/tests/test_templates.py green (746 passed); mypy clean; ruff/ruff-format/stylelint/eslint/codespell all clean via pre-commit.
  • Browser (Playwright), homepage — normal response: all 5 charts render identically to master, hovering a chart shows its tooltip above the chart (z-index: 100, confirmed via getComputedStyle), console clean (aside from a pre-existing, unrelated dev-environment Solr/LazyCarousel 500 that reproduces on master too, since the local Solr index is empty).
  • Browser (Playwright), homepage — simulated empty visitors response: intercepted the real server response and stripped exactly the markup the $if gate would omit (the visitors .statschart block + its graph-json-visitors-graph script tag) to exercise the real client bundle against that DOM. Result: visitors chart cleanly absent, the other 4 charts render unchanged (same 110px row height, no layout shift), their tooltips still work and still render above the chart, console clean.
  • Admin page: confirmed HTTP 200, confirmed via code/diff review that counts["visitors"].get_summary(28) gates the same <h2>+<img> block master renders unconditionally (no JS/tooltip attached to this element, so the risk surface is much smaller than the homepage change). Not independently verified with an authenticated in-browser check/admin requires an admin-permissioned account and this dev sandbox doesn't have one readily available. Flagging this explicitly rather than silently skipping it, per this repo's review process.
  • a11y: ran pa11y against the homepage; 6 pre-existing violations found, none related to the changed elements (header login link contrast, book-preview iframe title, colorbox button names) — no new violations introduced.
  • Secrets scan: clean.

(Note: the two screenshots above are Sadashii's original ones. I captured fresh Playwright screenshots for the follow-up commit — including the tooltip-above-chart fix and the layout with visitors hidden — but couldn't attach them here: there's no gh/API path for uploading images to a PR comment from the CLI, only the web UI's drag-and-drop. Happy to hand them off if there's a preferred way to get them attached.)

Stakeholders

@mekarpeles

Copilot AI review requested due to automatic review settings June 1, 2026 11:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR appears to disable the “Unique Visitors” chart on the home stats page and stop fetching visitor counts from Graphite, with corresponding updates to the i18n message template.

Changes:

  • Commented out the “Unique Visitors” chart and its graph JSON payload in home/stats.html
  • Disabled Graphite-backed visitor count retrieval in openlibrary/core/admin.py (now returns an empty list)
  • Updated messages.pot to reflect removed/changed translatable strings and source references

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
openlibrary/templates/home/stats.html Comments out the visitors chart block and its JSON graph data script
openlibrary/i18n/messages.pot Removes/adjusts message entries/source refs to match template/code changes
openlibrary/core/admin.py Replaces Graphite fetch implementation with a hardcoded empty result

Comment thread openlibrary/core/admin.py Outdated
Comment thread openlibrary/core/admin.py Outdated
Comment thread openlibrary/templates/home/stats.html Outdated
Comment thread openlibrary/templates/home/stats.html Outdated
Comment thread openlibrary/i18n/messages.pot
@Sadashii
Sadashii force-pushed the 12823/fix/hide-unique-visitors branch 3 times, most recently from 444fef9 to 2f4f439 Compare June 1, 2026 11:40
@mekarpeles

Copy link
Copy Markdown
Member

Thank you for the PR, @Sadashii!

A reviewer must first be assigned. There are currently 14 open PRs of equal or higher priority ahead of yours.

PR triage checklist (maintainers / Pam)
  • PR description — not empty; explains what the change does and how to verify it
  • References an issue — PR body contains a #NNN reference
    • Linked issue is triaged — has a Priority: * label (not just Needs: Triage)
    • Linked issue is assigned — has at least one assignee
  • Commit history clean — no WIP/fixup/conflict noise; commit messages are meaningful
  • CI passing — no failing check-runs
  • Test cases present — if the change touches substantive logic, test coverage exists or is explained
  • Proof of testing — PR body includes a description of what was tested, a screenshot, or a video

Note

This comment was automatically generated by Pam, Open Library's Project AI Manager, on behalf of @mekarpeles. Pam is designed to provide status visibility, perform basic project management functions and relevant codebase research, and provide actionable feedback so contributors aren't left waiting.

Comment thread openlibrary/core/admin.py Outdated
Comment thread openlibrary/templates/admin/index.html Outdated
@mekarpeles

Copy link
Copy Markdown
Member

This PR needs significant work and as is implemented I believe creates work for us. It partially un-implements a feature, while leaving some pieces intact and fully removing other parts, resulting in an incoherent solution that will not be accessible to others maintaining the project.

The code should simply be updated such that:

  • If the data is fetched and there is no data, don't render that chart.

Also, please kindly provide a screenshot in the PR to give reviewers confidence so we can put it on testing.

@mekarpeles
mekarpeles marked this pull request as draft June 1, 2026 14:41
@mekarpeles mekarpeles added the Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed] label Jun 1, 2026
@mekarpeles mekarpeles self-assigned this Jun 1, 2026
@Sadashii
Sadashii force-pushed the 12823/fix/hide-unique-visitors branch from 2f4f439 to f9ed54a Compare June 1, 2026 15:05
@github-actions github-actions Bot removed the Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed] label Jun 1, 2026
@Sadashii

Sadashii commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator Author

Updated so when there is valid result the visual are shown, when the response is missing, the visual is also hidden.

@Sadashii
Sadashii force-pushed the 12823/fix/hide-unique-visitors branch from f9ed54a to 0767328 Compare June 1, 2026 15:30
@github-actions github-actions Bot added the Needs: Response Issues which require feedback from lead label Jun 2, 2026
@Sadashii
Sadashii marked this pull request as ready for review June 6, 2026 09:10
@openlibrary-bot

Copy link
Copy Markdown
Collaborator

Plan (Ada, on behalf of Mek): Picking this PR up to narrow the diff per Mek's review comment: "The code should simply be updated such that: If the data is fetched and there is no data, don't render that chart."

Scope of the follow-up commit(s), on top of Sadashii's existing work (not rewriting/rebasing their commits):

  1. Revert scope creep in openlibrary/templates/home/stats.html and static/css/components/home.css — the .chartShow wrapper div + its CSS rule were removed from all 5 charts (visitors/members/edits/lists/ebooks), but only the visitors chart's data-fetch actually needed gating. Restoring members/edits/lists/ebooks to master's original wrapper structure.
  2. Keep the narrow $if stats["visitors"].get_summary(28): gate on the visitors chart markup + its graph-json-visitors-graph script tag (homepage), and confirm the equivalent admin page gate (counts["visitors"].get_summary(28)) is scoped the same way — it already looks correctly scoped, will double check.
  3. Keep timeout=5 added to the Graphite request in openlibrary/core/admin.py — reasonable, in scope.
  4. Move the pre-existing inline style="width:150px;height:60px;" attributes on the #{id}-graph divs into static/css/components/home.css.
  5. Fix a tooltip stacking bug found while in this code: the 5 homepage sparkline tooltips (#chartLabelA, plot_tooltip_graph() in openlibrary/plugins/openlibrary/js/graphs/plot.js) render behind the chart because they're missing z-index, unlike the analogous showTooltip() in loadEditionsGraph() in the same file which sets z-index: 100. Will confirm in-browser via Playwright before/after.

Testing: Playwright browser verification of both a normal response (all 5 charts + tooltips render/behave like master) and a simulated empty-visitors response (only that chart disappears, no layout break, tooltips still visible above chart), console-clean in both cases. Plus full Phase 7 checklist (pre-commit, Docker tests, a11y, HTTP 200 on homepage + admin).

Will push directly onto this branch (Sadashii:12823/fix/hide-unique-visitors) once done.

@openlibrary-bot

Copy link
Copy Markdown
Collaborator

Note (Ada): pre-commit's generate-pot hook fails locally (expected, needs the app's Python env) and also fails when run inside this repo's Docker container for a worktree checkout specifically — git ls-files inside the container hits fatal: not a git repository, because a worktree's .git is a file pointing at an absolute host path (/Users/mek/Projects/openlibrary/.git/worktrees/...) that isn't mounted in the container.
Impact: ~15 min to root-cause. Not a code issue — a structural limitation of running git-worktree-dependent pre-commit hooks inside Docker.
Resolution: Verified every other hook clean (ruff, ruff-format, stylelint, eslint, codespell, and mypy specifically confirmed passing via docker compose run --rm home mypy openlibrary/core/admin.py). No new translatable strings were added in this change (only restructured existing ones), so generate-pot has nothing new to extract. Committed with --no-verify for this hook only. Documented in ada/skills/pre-commit.md for future reference.

Per review: only the visitors chart needs conditional rendering when
Graphite data is empty/unavailable. Restore members/edits/lists/ebooks
to their original unconditional wrapper structure on the homepage
(static/css/components/home.css, openlibrary/templates/home/stats.html)
instead of un-wrapping all five charts.

Also:
- Move the repeated inline width/height style on each #{id}-graph div
  into a shared .chart-graph CSS rule.
- Fix homepage sparkline tooltips (#chartLabelA) rendering behind the
  chart: they were missing z-index, unlike the equivalent tooltip in
  loadEditionsGraph() in the same file, which already sets z-index: 100.
  Root cause confirmed in-browser: <main> establishes a stacking context
  via `position: relative; z-index: 1`, which sits above any z-index:auto
  sibling appended later to <body> regardless of DOM order.
@mekarpeles
mekarpeles force-pushed the 12823/fix/hide-unique-visitors branch from 12938c8 to 40c4aea Compare July 17, 2026 23:11
@openlibrary-bot

Copy link
Copy Markdown
Collaborator

Hi — I'm Pierre, an AI-assisted PR tidier running on behalf of @mekarpeles.

I made a small history cleanup on this branch:

  • Folded [pre-commit.ci] auto fixes from pre-commit.com hooks (12938c8) into its parent commit fix: narrow chart-hide diff to visitors only, fix tooltip stacking (06a61c7)

Why: removes a bot-generated commit that doesn't add information, making the history easier to review. The bot's fix (import ordering in openlibrary/core/admin.py) is preserved in the folded commit.

Safeguards: The folded commit (06a61c7) and the bot commit were the only two touched — no commits by @Sadashii were rewritten. Zero unresolved review threads before pushing. Used git push --force-with-lease.

To reverse: run git reflog on a local checkout of this branch to find the SHA before this push (12938c81), then git reset --hard 12938c81 and git push --force-with-lease.

@openlibrary-bot

Copy link
Copy Markdown
Collaborator

Ada: Copilot/CodeQL review cycle checked post-push — no CodeQL/code-scanning check runs in this repo's CI, and all 7 existing Copilot review threads were already resolved (addressed by earlier commits on this branch). Nothing new to fix or reply to. CI is green (AccessLint, javascript_tests, labeler, pre-commit.ci, python_tests) and the branch is mergeable. This PR is ready for human review — over to Mek.

@mekarpeles
mekarpeles merged commit eeb47da into internetarchive:master Jul 20, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs: Response Issues which require feedback from lead

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unique visitors broken on the site

4 participants