Skip to content

perf(stats): use queued project context - #13480

Closed
loks0n wants to merge 1 commit into
mainfrom
codex/stats-usage-project-context
Closed

loks0n wants to merge 1 commit into
mainfrom
codex/stats-usage-project-context

Conversation

@loks0n

@loks0n loks0n commented Sep 4, 2026 •

Copy link
Copy Markdown
Member

What changed

  • inject the typed ProjectContext into the stats-usage worker instead of resolving the current project document
  • retain the queued payload/context project ID consistency check
  • use the queued project sequence as the usage tenant

Why

Usage is event-time data. Resolving the mutable platform project for every queued usage message adds a platform database/cache read and can discard attribution when a project is deleted before its already-enqueued usage is consumed. The message already carries the immutable identity needed by this worker.

Cloud has a separate batched stats-usage implementation that already consumes the queued project payload without resolving the platform project. This change optimizes the CE worker path.

Verification

  • php -l src/Appwrite/Platform/Workers/StatsUsage.php
  • Pint on src/Appwrite/Platform/Workers/StatsUsage.php
  • PHPStan on src/Appwrite/Platform/Workers/StatsUsage.php

No worker unit test was added because this repository requires worker behavior to be covered through E2E rather than unit-testing action internals; this dependency-only change has no dedicated stats-usage E2E seam.

@greptile-apps

greptile-apps Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR removes the platform-database project lookup from the usage worker and uses the project identity and sequence already carried by each queued usage message.

  • Replaces the injected project document with ProjectContext.
  • Uses the queued project sequence as the usage tenant.
  • Preserves payload validation and handling for missing project sequences.

Confidence Score: 5/5

The PR appears safe to merge because the worker resource is available and existing usage messages already carry the required project ID and sequence.

The changed worker consumes the same project fields serialized by the established usage-message producer, while avoiding the previous database lookup; no build, compatibility, or tenant-attribution failure remains.

Important Files Changed

Filename Overview
src/Appwrite/Platform/Workers/StatsUsage.php Uses the existing queued project context instead of loading the project document for each usage event; no actionable defect was identified.

Reviews (1): Last reviewed commit: "perf(stats): use queued project context" | Re-trigger Greptile

@loks0n

loks0n commented Sep 4, 2026

Copy link
Copy Markdown
Member Author

Closing because the optimization is CE-only; Appwrite Cloud already avoids this project lookup in its custom stats-usage worker.

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