diff options
author | Santo Cariotti <santo@dcariotti.me> | 2024-09-09 16:28:08 +0200 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2024-09-09 16:28:08 +0200 |
commit | bb84f440b02632df13f16d040b1aa9a220ec535d (patch) | |
tree | 4b846e37123d89b6dcb404edcf6a36e616b71954 /src | |
parent | b4478d84ee3cc2bd5491f7c16d63531bdd466918 (diff) |
Fix query to get positions for notifications
Diffstat (limited to 'src')
-rw-r--r-- | src/graphql/types/alert.rs | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/graphql/types/alert.rs b/src/graphql/types/alert.rs index 41ae4de..f74023a 100644 --- a/src/graphql/types/alert.rs +++ b/src/graphql/types/alert.rs @@ -259,12 +259,17 @@ pub mod mutations { let position_ids: Vec<i32> = client .query( - " - SELECT id FROM positions + "SELECT id + FROM positions p WHERE ST_DWithin( - location::geography, - (SELECT area::geography FROM alerts WHERE id = $1), - $2 + p.location::geography, + (SELECT area::geography FROM alerts WHERE id = $1), + $2 + ) + AND id = ( + SELECT MAX(id) + FROM positions + WHERE user_id = p.user_id )", &[&alert.id, &distance], ) @@ -295,7 +300,7 @@ pub mod mutations { .map(|i| format!("${}", i)) .collect(); let query = format!( - "SELECT u.notification_token FROM positions p JOIN users u ON u.id = p.user_id + "SELECT DISTINCT u.notification_token FROM positions p JOIN users u ON u.id = p.user_id WHERE p.id IN ({}) AND notification_token IS NOT NULL", placeholders.join(", ") ); |