Skip to content

Network page: async stats, faster stats query, exclude archived groups from count - #911

Open
edwh wants to merge 4 commits into
developfrom
network-stats-and-group-country
Open

edwh wants to merge 4 commits into
developfrom
network-stats-and-group-country

Conversation

@edwh

@edwh edwh commented Sep 23, 2026 •

Copy link
Copy Markdown
Collaborator

For #927. The group country fix that was in here has been split out and merged as #916.

Summary

  • Faster network page. Before, the page waited for the network's impact figures to be worked out, which took a long time for big networks like Hauts-de-France or Repair Together. Now the page shows straight away, with "…" in the figures until they arrive. If loading them fails, the figures show "–".
  • Groups figure leaves out archived groups. Before, the number of groups on a network page counted archived groups too. Now it counts only active groups. Archived groups' past events still count towards events, waste and CO2, because those repairs did happen.
  • Faster to work out. The impact figures are calculated with quicker database queries. The "Add groups" list on the network page loads less data.
  • Each event counted once. Paging through events by id needs the id to be the only sort order; otherwise, on networks with many events, some events would be skipped and others counted twice. The query sorts by id only, so each event is counted exactly once.

What changes in the API

  • GET /api/networks/{id}/stats now includes groups: the number of non-archived groups in the network. The network page uses this.
  • The same stats filtered by group tag also return groups, counted the same way.
  • Nothing has been removed from the responses.

Code Quality Review

  • The network page reuses the existing stats API endpoint, rather than adding another.
  • bulkGroupStats pages through events by id instead of by offset, which is what made it slow.

Test Plan

  • PHPUnit: 450 events across two groups, with dates running in the opposite order to their ids, are each counted exactly once.
  • PHPUnit: network and API tests for the groups figure.
  • Neil to review on the preview.

Comment thread tests/TestCase.php Fixed
Comment thread tests/TestCase.php Fixed
@ngm

ngm commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

@edwh Could you split this into different PRs please? I prefer to have them more atomic where possible.

…from group count

- The network page no longer calculates stats before rendering; the Vue
  component fetches them from the API (it already did when initialStats was
  empty), showing "…" until they arrive.
- Network::stats() loads only group ids (no member-count scopes or eager
  loads), and bulkGroupStats pages events by primary key instead of a growing
  OFFSET. The "add groups" picker selects only id and name.
- stats() returns 'groups', counting only non-archived groups; impact stats
  still include archived groups' past events.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@edwh
edwh force-pushed the network-stats-and-group-country branch from 734dbb3 to 0280645 Compare September 23, 2026 15:05
@edwh edwh changed the title Network stats speed + archived group count, group country fill, faster PHPUnit setup Network page: async stats, faster stats query, exclude archived groups from count Sep 23, 2026
edwh and others added 3 commits September 25, 2026 16:26
…iled-load state

- bulkGroupStats(): reorder() before lazyById. past() orders by date, and
  lazyById only strips an existing order on the id column, so pages were
  ordered by date and paged by id: events beyond the first 200 were skipped
  or double-counted (399 of 450 in the new test).
- statsForTag() returns 'groups' like Network::stats().
- NetworkPage shows '–' if the stats request fails, not '…' forever.
- StatsTestCase declares $_ratioPowered (dynamic property deprecation hid
  test failure messages under process isolation).

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

Copy link
Copy Markdown

This branch has not been deployed

No deployments
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.

3 participants