As part of the discussion of T235572, @jcrespo pointed out that making big database queries to get counts of edits is inefficient. Instead, we should store the counts in a separate database table, and update that table when a new revision is created.
We've currently got API endpoints for the following counts:
- Bot-authored revisions
- Anonymous-authored revisions
- Minor revisions
- Total revisions
A revision_counts table could contain the page ID as the primary key, and each of these counts as a column (bot_revisions, anon_revisions, minor_revisions, total_revisions).
When a page is saved and a new revision is created, we should increment the total edits for that page, and also the applicable edits (for example, if it's a minor revision, increment the minor revisions count).
To backfill counts that don't exist, we can do the necessary queries to determine the counts at edit time or at API call time. Since edit volume is much much bigger than expected API traffic, it probably makes sense to do it at API call time, and only increment at edit time if the revision_counts row for the page already exists.
We'll also need code to decrement the counts when a revision is deleted, and increment the counts when a revision is undeleted.