Skip to content

Commit

Permalink
Optimize site filtering by slice during SiteAlert creation for geosta…
Browse files Browse the repository at this point in the history
…tionary satellites.
  • Loading branch information
dhakalaashish committed Apr 23, 2024
1 parent b01dc0b commit 2b8e193
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions apps/server/src/Services/GeoEvent/GeoEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ const processGeoEvents = async (geoEventProviderClientId: GeoEventProviderClient
// having the provided providerKey
const geoEvents = await prisma.geoEvent.findMany({
select: { id: true },
// IMPROVEMENT: this code does not identify duplicate between providers,
// It only identifies duplicate within a provider
// To identify duplicates between providers, remove geoEventProviderId from the where clause
// However, that would increase memory usage, and possibly freeze the process
// Identify ways to test for duplication against the entire database.
where: { geoEventProviderId: geoEventProviderId, eventDate: { gt: new Date(Date.now() - 30 * 60 * 60 * 1000) } },
});
// Only compare with data from last 26 hrs
Expand Down
10 changes: 10 additions & 0 deletions apps/server/src/Services/SiteAlert/CreateSiteAlert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ const createSiteAlerts = async (
AND (s."stopAlertUntil" IS NULL OR s."stopAlertUntil" < CURRENT_TIMESTAMP)
AND e."isProcessed" = FALSE
AND e. "geoEventProviderId" = ${geoEventProviderId}
AND EXISTS (
SELECT 1
FROM jsonb_array_elements_text(s.slices) AS slice_element
WHERE slice_element = ANY(string_to_array(${Prisma.raw(`'${slice}'`)}, ',')::text[])
)
AND ST_Within(ST_SetSRID(ST_MakePoint(e.longitude, e.latitude), 4326), ST_GeomFromEWKB(decode(dg_elem, 'hex')))
AND NOT EXISTS (
SELECT 1
Expand Down Expand Up @@ -70,6 +75,11 @@ const createSiteAlerts = async (
AND e."isProcessed" = FALSE
AND e. "geoEventProviderId" = ${geoEventProviderId}
AND (s.type = 'Polygon' OR s.type = 'Point')
AND EXISTS (
SELECT 1
FROM jsonb_array_elements_text(s.slices) AS slice_element
WHERE slice_element = ANY(string_to_array(${Prisma.raw(`'${slice}'`)}, ',')::text[])
)
AND NOT EXISTS (
SELECT 1
FROM "SiteAlert"
Expand Down

0 comments on commit 2b8e193

Please sign in to comment.