Skip to content

perf(logs): read the unfiltered query log count from the maintained counter - #279

Merged
henry40408 merged 2 commits into
mainfrom
perf/logs-count-counter
Sep 13, 2026
Merged

henry40408 merged 2 commits into
mainfrom
perf/logs-count-counter

Conversation

@henry40408

@henry40408 henry40408 commented Sep 13, 2026

Copy link
Copy Markdown
Owner

Summary

The query log's pager asks count_logs for its total on every load. With no filter applied, that total is just the table's row count. The insert batch, the prune and Clear All already maintain that number in settings (query_log_count) for the Database Health card, but count_logs counted it again, walking the smallest index end to end.

  • count_logs: reads the counter when append_log_filters added no condition. That covers a blank search box too. Any filter still counts.
  • read_log_count: the counter read total_log_count already did, pulled out so both callers share it. Its fallback to COUNT(*) when the counter row is missing is unchanged.

Page misses

logs_page_miss_bench, same database copies and BENCH_NOW=1789212354 as the #278 baseline:

370 677 rows      no filter — count      1387 ->     3    SUM OF ALL READINGS  104829 -> 103445
1 482 708 rows    no filter — count      6230 ->     3    SUM OF ALL READINGS  380823 -> 374596

The other 41 readings are identical before and after on both databases.

Tests

  • New: the_unfiltered_query_log_count_is_read_rather_than_counted (tests/stats_page_miss_test.rs). Before the change it failed with no filter read 67 pages and counting the same rows read 172; after the change it passes. It covers both no filter and a blank search.
  • the_log_count_follows_every_write_that_changes_it: used count_logs(None, …) as its independent "real count", which now reads the counter itself. It checks against the rows returned by query_logs instead, and adds the blank-search case.
  • the_total_log_count_is_read_rather_than_counted: also used an unfiltered count_logs as its counted baseline. It now uses a * search, which matches every row.
  • e2e fixtures: fixtures are written with the sqlite3 CLI, so they bypass the write paths that maintain the counter. On the first CI run, logs_no_js showed Page 1 / 1 for a three-page fixture (#log-pagination contains "Page 1 / 3": last saw "Prev Page 1 / 1 Next"). Server::seed now recomputes query_log_count after every fixture, which also keeps the Database Health card correct on seeded instances. Locally, cargo test --test specs ends with all spec cases passed.

Test plan

  • cargo fmt --check
  • cargo clippy --all-targets -- -D warnings
  • cargo nextest run: 681 passed, 8 skipped
  • logs_page_miss_bench before/after on both databases
  • cd e2e && cargo test --test specs: all spec cases passed

🤖 Generated with Claude Code

…ounter

The query log's pager asks count_logs for its total on every load. With
no filter applied that total is the table's row count, which the insert
batch, the prune and Clear All already maintain in settings for the
Database Health card. Counting it instead walked the smallest index end
to end.

count_logs now reads the counter when append_log_filters added no
condition, which also covers a blank search box, through the same
read_log_count total_log_count uses. Any filter still counts.

logs_page_miss_bench, unfiltered count:
- 370 677-row database: 1 387 -> 3 pages
- 1 482 708-row database: 6 230 -> 3 pages
Every other reading is unchanged.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Sep 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.16%. Comparing base (c28f4a2) to head (4aebdcb).

Files with missing lines Patch % Lines
src/db.rs 85.71% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #279      +/-   ##
==========================================
+ Coverage   91.14%   91.16%   +0.01%     
==========================================
  Files          31       31              
  Lines       11401    11400       -1     
==========================================
+ Hits        10392    10393       +1     
+ Misses       1009     1007       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Fixtures are written with the sqlite3 CLI, so they bypass the write
paths that maintain query_log_count. The unfiltered query log count now
reads that counter, which left logs_no_js reporting "Page 1 / 1" for a
fixture holding three pages. Server::seed now recomputes the counter
after every fixture, which also keeps the Database Health card honest
on seeded instances.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@henry40408
henry40408 merged commit ea08a65 into main Sep 13, 2026
7 checks passed
@henry40408
henry40408 deleted the perf/logs-count-counter branch September 13, 2026 15:53
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.

1 participant