Repository navigation
Conversation
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
force-pushed
the
perf/platform-stats-direct-db-counts
branch
from
September 26, 2026 00:44
7754e22 to
8699b3c
Compare
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.
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