Skip to content
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

[#175497433] Add Profile unsubscription on feed #86

Merged
merged 4 commits into from
Nov 3, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions GetSubscriptionsFeed/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ export function GetSubscriptionsFeedHandler(
const profileSubscriptionsQuery: PagedQuery = pagedQuery(
queryFilterForKey(`P-${subscriptionsDateUTC}-S`)
);
const profileUnsubscriptionsQuery: PagedQuery = pagedQuery(
queryFilterForKey(`P-${subscriptionsDateUTC}-U`)
);
const serviceSubscriptionsQuery: PagedQuery = pagedQuery(
queryFilterForKey(`S-${subscriptionsDateUTC}-${serviceId}-S`)
);
Expand All @@ -117,6 +120,11 @@ export function GetSubscriptionsFeedHandler(
// users that created their account on date
const profileSubscriptionsSet = await queryUsers(profileSubscriptionsQuery);

// users that deleted their account on date
const profileUnsubscriptionsSet = await queryUsers(
profileUnsubscriptionsQuery
);

// users that subscribed to the client service on date
const serviceSubscriptionsSet = await queryUsers(serviceSubscriptionsQuery);

Expand All @@ -134,7 +142,10 @@ export function GetSubscriptionsFeedHandler(
}
});
serviceSubscriptionsSet.forEach(ss => {
if (!profileSubscriptionsSet.has(ss)) {
if (
!profileSubscriptionsSet.has(ss) &&
!profileUnsubscriptionsSet.has(ss)
) {
// add all users that subscribed to this service, skipping those that
// are new users as they're yet counted in as new subscribers in the
// previous step
Expand All @@ -143,11 +154,20 @@ export function GetSubscriptionsFeedHandler(
});

const unsubscriptions = new Array<FiscalCodeHash>();

profileUnsubscriptionsSet.forEach(pu =>
// add all users that deleted its own account
unsubscriptions.push(pu)
);

serviceUnsubscriptionsSet.forEach(su => {
if (!profileSubscriptionsSet.has(su)) {
if (
!profileSubscriptionsSet.has(su) &&
!profileUnsubscriptionsSet.has(su)
) {
// add all users that unsubscribed from this service, skipping those
// that created the profile on the same day as the service will not
// yet know they exist
// yet know they exist or deleted their account
unsubscriptions.push(su);
}
});
Expand Down