From d94a25bbd2632eb07db368168e8c5b867456e4bb Mon Sep 17 00:00:00 2001 From: Johan Brandhorst-Satzkorn Date: Wed, 20 Dec 2023 10:39:48 -0800 Subject: [PATCH] internal/host: sort public_id descending The previous sort would run the risk of missing items which collide on update or create times because of the compound comparison using strictly less than for both the timestamp and the public_id. Sorting both descending avoids thi issue. --- .../oss/postgres/80/09_host_table_updates.up.sql | 8 ++++---- internal/host/plugin/query.go | 16 ++++++++-------- internal/host/static/query.go | 16 ++++++++-------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/internal/db/schema/migrations/oss/postgres/80/09_host_table_updates.up.sql b/internal/db/schema/migrations/oss/postgres/80/09_host_table_updates.up.sql index cccf646a16..f5eef1a047 100644 --- a/internal/db/schema/migrations/oss/postgres/80/09_host_table_updates.up.sql +++ b/internal/db/schema/migrations/oss/postgres/80/09_host_table_updates.up.sql @@ -5,17 +5,17 @@ begin; -- Add new indexes for the create time and update time queries. create index host_plugin_host_create_time_public_id_idx - on host_plugin_host (create_time desc, public_id asc); + on host_plugin_host (create_time desc, public_id desc); create index host_plugin_host_update_time_public_id_idx - on host_plugin_host (update_time desc, public_id asc); + on host_plugin_host (update_time desc, public_id desc); analyze host_plugin_host; -- Add new indexes for the create time and update time queries. create index static_host_create_time_public_id_idx - on static_host (create_time desc, public_id asc); + on static_host (create_time desc, public_id desc); create index static_host_update_time_public_id_idx - on static_host (update_time desc, public_id asc); + on static_host (update_time desc, public_id desc); analyze static_host; diff --git a/internal/host/plugin/query.go b/internal/host/plugin/query.go index afbf86abb0..c1a27b4bff 100644 --- a/internal/host/plugin/query.go +++ b/internal/host/plugin/query.go @@ -72,7 +72,7 @@ with hosts as ( version from host_plugin_host where catalog_id = @catalog_id - order by create_time desc, public_id asc + order by create_time desc, public_id desc limit %d ), host_catalog as ( @@ -126,7 +126,7 @@ final as ( ) select * from final -order by create_time desc, public_id asc; +order by create_time desc, public_id desc; ` listHostsPageTemplate = ` @@ -143,7 +143,7 @@ with hosts as ( from host_plugin_host where catalog_id = @catalog_id and (create_time, public_id) < (@last_item_create_time, @last_item_id) - order by create_time desc, public_id asc + order by create_time desc, public_id desc limit %d ), host_catalog as ( @@ -197,7 +197,7 @@ final as ( ) select * from final -order by create_time desc, public_id asc; +order by create_time desc, public_id desc; ` listHostsRefreshTemplate = ` @@ -214,7 +214,7 @@ with hosts as ( from host_plugin_host where catalog_id = @catalog_id and update_time > @updated_after_time - order by update_time desc, public_id asc + order by update_time desc, public_id desc limit %d ), host_catalog as ( @@ -268,7 +268,7 @@ final as ( ) select * from final -order by update_time desc, public_id asc; +order by update_time desc, public_id desc; ` listHostsRefreshPageTemplate = ` @@ -286,7 +286,7 @@ with hosts as ( where catalog_id = @catalog_id and update_time > @updated_after_time and (update_time, public_id) < (@last_item_update_time, @last_item_id) - order by update_time desc, public_id asc + order by update_time desc, public_id desc limit %d ), host_catalog as ( @@ -340,7 +340,7 @@ final as ( ) select * from final -order by update_time desc, public_id asc; +order by update_time desc, public_id desc; ` estimateCountHostSets = ` diff --git a/internal/host/static/query.go b/internal/host/static/query.go index a3b8bad449..b64a0ef56b 100644 --- a/internal/host/static/query.go +++ b/internal/host/static/query.go @@ -63,7 +63,7 @@ with hosts as ( version from static_host where catalog_id = @catalog_id - order by create_time desc, public_id asc + order by create_time desc, public_id desc limit %d ), host_set_ids as ( @@ -88,7 +88,7 @@ final as ( ) select * from final -order by create_time desc, public_id asc; +order by create_time desc, public_id desc; ` listHostsPageTemplate = ` @@ -104,7 +104,7 @@ with hosts as ( from static_host where catalog_id = @catalog_id and (create_time, public_id) < (@last_item_create_time, @last_item_id) - order by create_time desc, public_id asc + order by create_time desc, public_id desc limit %d ), host_set_ids as ( @@ -129,7 +129,7 @@ final as ( ) select * from final -order by create_time desc, public_id asc; +order by create_time desc, public_id desc; ` listHostsRefreshTemplate = ` @@ -145,7 +145,7 @@ with hosts as ( from static_host where catalog_id = @catalog_id and update_time > @updated_after_time - order by update_time desc, public_id asc + order by update_time desc, public_id desc limit %d ), host_set_ids as ( @@ -170,7 +170,7 @@ final as ( ) select * from final -order by update_time desc, public_id asc; +order by update_time desc, public_id desc; ` listHostsRefreshPageTemplate = ` with hosts as ( @@ -186,7 +186,7 @@ with hosts as ( where catalog_id = @catalog_id and update_time > @updated_after_time and (update_time, public_id) < (@last_item_update_time, @last_item_id) - order by update_time desc, public_id asc + order by update_time desc, public_id desc limit %d ), host_set_ids as ( @@ -211,7 +211,7 @@ final as ( ) select * from final -order by update_time desc, public_id asc; +order by update_time desc, public_id desc; ` estimateCountHostSets = `