fix: Optimize campaign reach using batched school metrics queries and campaign reach queries#4740
Conversation
…ate Parent WhatsApp Invitation feature.
There was a problem hiding this comment.
Code Review
This pull request refactors the campaign reach calculation to batch school ID queries and introduces a new API method, getCampaignParentsInGroupBySchoolIds, to fetch pre-aggregated parent metrics from the database. Feedback on these changes highlights a few critical issues: first, calling the optional API methods getParentWhatsappClassesBySchoolId and getCampaignParentsInGroupBySchoolIds in useCampaignReach.ts without non-null assertions will trigger TypeScript compilation errors; second, the SqliteApi class is missing an implementation for the newly added getCampaignParentsInGroupBySchoolIds method, which will lead to runtime failures.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| const schoolClasses = | ||
| await api.getParentWhatsappClassesBySchoolId(selectedSchoolIds); |
There was a problem hiding this comment.
Since getParentWhatsappClassesBySchoolId is an optional method on the API interface, calling it directly without the non-null assertion operator (!) will cause a TypeScript compilation error under strict null checks. Please restore the ! operator.
| const schoolClasses = | |
| await api.getParentWhatsappClassesBySchoolId(selectedSchoolIds); | |
| const schoolClasses = | |
| await api.getParentWhatsappClassesBySchoolId!(selectedSchoolIds); |
| const memberCount = | ||
| await api.getCampaignParentsInGroupBySchoolIds(selectedSchoolIds); |
There was a problem hiding this comment.
Since getCampaignParentsInGroupBySchoolIds is an optional method on the API interface, calling it directly without the non-null assertion operator (!) will cause a TypeScript compilation error under strict null checks. Please add the ! operator.
| const memberCount = | |
| await api.getCampaignParentsInGroupBySchoolIds(selectedSchoolIds); | |
| const memberCount = | |
| await api.getCampaignParentsInGroupBySchoolIds!(selectedSchoolIds); |
| } | ||
| return await this._serverApi.getParentWhatsappClassesBySchoolId(schoolId); | ||
| return await this._serverApi.getParentWhatsappClassesBySchoolId(schoolIds); | ||
| } |
There was a problem hiding this comment.
The SqliteApi class implements ServiceApi, but it is missing the implementation for the new getCampaignParentsInGroupBySchoolIds method. If SqliteApi is active (e.g., in local or offline environments), calling this method via ApiHandler will throw an error because this.s.getCampaignParentsInGroupBySchoolIds is undefined.
Please implement getCampaignParentsInGroupBySchoolIds in SqliteApi to forward the call to _serverApi (similar to getParentWhatsappClassesBySchoolId).
}
async getCampaignParentsInGroupBySchoolIds(
schoolIds: string[],
): Promise<number> {
if (!this._serverApi || !this._serverApi.getCampaignParentsInGroupBySchoolIds) {
throw new Error(
'Campaign parents-in-group metrics lookup is not implemented in Supabase API.',
);
}
return await this._serverApi.getCampaignParentsInGroupBySchoolIds(schoolIds);
}There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 60f55674c3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const memberCount = | ||
| await api.getCampaignParentsInGroupBySchoolIds(selectedSchoolIds); |
There was a problem hiding this comment.
Preserve reach metrics in SQLite mode
When the app is initialized with APIMode.SQLITE, api is still an ApiHandler, so the earlier method-existence guard passes because ApiHandler defines getCampaignParentsInGroupBySchoolIds; however SqliteApi does not implement this optional delegate, unlike the existing class/parent-phone WhatsApp delegates, so this call throws Campaign parents-in-group metrics lookup is not implemented.... The previous implementation worked in SQLite mode via the existing delegates, but campaign setup/communication now logs an error and leaves the reach widget empty or stale in that environment; please add the SQLite-to-Supabase delegate or keep a fallback path.
Useful? React with 👍 / 👎.
No description provided.