Skip to content

perf: query platform wiki entity counts directly - #1276

Open
addshore wants to merge 1 commit into
wbstack:mainfrom
addshore:perf/platform-stats-direct-db-counts
Open

addshore wants to merge 1 commit into
wbstack:mainfrom
addshore:perf/platform-stats-direct-db-counts

Conversation

@addshore

Copy link
Copy Markdown
Collaborator

Improves some SQL queries as part of T424505, but the main changes is the removal of API calls entirely.

Replace per-wiki API requests with a single direct database query and avoid WikiDb N+1 lookups when preparing platform statistics.

Restore PlatformStatsSummaryJob integration coverage by isolating non-transactional MediaWiki schema and user provisioning from Laravel's RefreshDatabase transaction.

Looking by eye, at https://www.wikibase.cloud/discovery there are certianly 7+ million "pages" that are on cloud Which would reuslt in 14k http requests being made probably with 500 results per page (lots of overheads)

The description of the origional ticket at
https://phabricator.wikimedia.org/T314481
links to
https://gerrit.wikimedia.org/g/analytics/wmde/scripts/+/3c0f9791912774bae41546412a048d2019b74b4b/src/wikidata/site_stats/pages_by_namespace.php and nearby
https://gerrit.wikimedia.org/r/plugins/gitiles/analytics/wmde/scripts/+/3c0f9791912774bae41546412a048d2019b74b4b/src/wikidata/site_stats/sql/select_pages_by_namespace.sql which shows how wikidata has been doing this for some time.

When testing locally on a page table with 1 million rows the qury still returns quickly, and I expect this will also be quick enough (and better than the API calls) in wb cloud.

Bug: T314481
Bug: T424505

Improves some SQL queries as part of T424505, but the main
changes is the removal of API calls entirely.

Replace per-wiki API requests with a single direct database query and
avoid WikiDb N+1 lookups when preparing platform statistics.

Restore PlatformStatsSummaryJob integration coverage by isolating
non-transactional MediaWiki schema and user provisioning from Laravel's
RefreshDatabase transaction.

Looking by eye, at https://www.wikibase.cloud/discovery
there are certianly 7+ million "pages" that are on cloud
Which would reuslt in 14k http requests being made probably
with 500 results per page (lots of overheads)

The description of the origional ticket at
https://phabricator.wikimedia.org/T314481
links to
https://gerrit.wikimedia.org/g/analytics/wmde/scripts/+/3c0f9791912774bae41546412a048d2019b74b4b/src/wikidata/site_stats/pages_by_namespace.php
and nearby
https://gerrit.wikimedia.org/r/plugins/gitiles/analytics/wmde/scripts/+/3c0f9791912774bae41546412a048d2019b74b4b/src/wikidata/site_stats/sql/select_pages_by_namespace.sql
which shows how wikidata has been doing this for some time.

When testing locally on a page table with 1 million rows
the qury still returns quickly, and I expect this will also
be quick enough (and better than the API calls) in wb cloud.

Another thing to consider here is that this single query is getting
rather large, and that group_concat_max_len might be reached depending
on the prod setup, if you are not there already, your liekly getting there
soon.
The query could be split easily into appropriate sized chunks and join
the results later, OR increase group_concat_max_len

Bug: T314481
Bug: T424505
@addshore
addshore force-pushed the perf/platform-stats-direct-db-counts branch from 7754e22 to 8699b3c Compare September 26, 2026 00:44
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