-
Notifications
You must be signed in to change notification settings - Fork 16
fix: Optimize campaign reach using batched school metrics queries and campaign reach queries #4740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,47 +21,29 @@ export const useCampaignReach = (selectedSchoolIds: string[]) => { | |||||||||
| if ( | ||||||||||
| selectedSchoolIds.length === 0 || | ||||||||||
| !api.getParentWhatsappClassesBySchoolId || | ||||||||||
| !api.getParentWhatsappParentPhonesByClassId | ||||||||||
| !api.getCampaignParentsInGroupBySchoolIds | ||||||||||
| ) { | ||||||||||
| setCampaignReach(emptyReach); | ||||||||||
| return; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| setLoadingReach(true); | ||||||||||
| try { | ||||||||||
| const schoolClasses = await Promise.all( | ||||||||||
| selectedSchoolIds.map((schoolId) => | ||||||||||
| api.getParentWhatsappClassesBySchoolId!(schoolId), | ||||||||||
| ), | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| const groupedClasses = schoolClasses | ||||||||||
| .flat() | ||||||||||
| .filter( | ||||||||||
| (classRow) => | ||||||||||
| classRow.group_id && String(classRow.group_id).trim() !== '', | ||||||||||
| ); | ||||||||||
| const schoolClasses = | ||||||||||
| await api.getParentWhatsappClassesBySchoolId(selectedSchoolIds); | ||||||||||
|
|
||||||||||
| const memberLists = await Promise.all( | ||||||||||
| groupedClasses.map(async (classRow) => { | ||||||||||
| try { | ||||||||||
| const phones = await api.getParentWhatsappParentPhonesByClassId!( | ||||||||||
| classRow.id, | ||||||||||
| ); | ||||||||||
| return Array.from(new Set(phones)); | ||||||||||
| } catch { | ||||||||||
| return []; | ||||||||||
| } | ||||||||||
| }), | ||||||||||
| const groupedClasses = schoolClasses.filter( | ||||||||||
| (classRow) => | ||||||||||
| classRow.group_id && String(classRow.group_id).trim() !== '', | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| const memberCount = | ||||||||||
| await api.getCampaignParentsInGroupBySchoolIds(selectedSchoolIds); | ||||||||||
|
Comment on lines
+40
to
+41
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since
Suggested change
Comment on lines
+40
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When the app is initialized with Useful? React with 👍 / 👎. |
||||||||||
|
|
||||||||||
| if (!mounted) return; | ||||||||||
| setCampaignReach({ | ||||||||||
| groupCount: groupedClasses.length, | ||||||||||
| memberCount: memberLists.reduce( | ||||||||||
| (total, members) => total + members.length, | ||||||||||
| 0, | ||||||||||
| ), | ||||||||||
| memberCount, | ||||||||||
| }); | ||||||||||
| } catch (error) { | ||||||||||
| logger.error('Failed to load campaign reach:', error); | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7316,7 +7316,7 @@ order by | |
| } | ||
|
|
||
| // Parent WhatsApp Invitation: class lookup with group/invite fields. | ||
| async getParentWhatsappClassesBySchoolId(schoolId: string): Promise< | ||
| async getParentWhatsappClassesBySchoolId(schoolIds: string[]): Promise< | ||
| { | ||
| id: string; | ||
| name: string; | ||
|
|
@@ -7329,7 +7329,7 @@ order by | |
| 'Parent WhatsApp class lookup is not implemented in Supabase API.', | ||
| ); | ||
| } | ||
| return await this._serverApi.getParentWhatsappClassesBySchoolId(schoolId); | ||
| return await this._serverApi.getParentWhatsappClassesBySchoolId(schoolIds); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Please implement }
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);
} |
||
|
|
||
| // Parent WhatsApp Invitation: parent phones from class_user -> user join. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
getParentWhatsappClassesBySchoolIdis 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.