Further optimize intermediate row fetching by filtering scids first
[rapid-gossip-sync-server] / src / lookup.rs
index 263514d81bbd9ba13df32ff47822caaef73adfef..c554f9f57508bb251d7f664a26cd2ec0eee3ae2d 100644 (file)
@@ -225,12 +225,12 @@ pub(super) async fn fetch_channel_updates(delta_set: &mut DeltaSet, client: &Cli
                WHERE id IN (
                        SELECT DISTINCT ON (short_channel_id, direction) id
                        FROM channel_updates
-                       WHERE seen < $1
+                       WHERE seen < $1 AND short_channel_id IN (
+                               SELECT DISTINCT ON (short_channel_id) short_channel_id
+                               FROM channel_updates
+                               WHERE seen >= $1
+                       )
                        ORDER BY short_channel_id ASC, direction ASC, seen DESC
-               ) AND short_channel_id IN (
-                       SELECT DISTINCT ON (short_channel_id) short_channel_id
-                       FROM channel_updates
-                       WHERE seen >= $1
                )
                ", [last_sync_timestamp_object]).await.unwrap();
        let mut pinned_rows = Box::pin(reference_rows);