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 this issue.
This commit is contained in:
1 parent
a8c360ebf4
commit
b3207d8e1c
3 files changed
+14
-14
No files matched your search
@@ -5,17 +5,17 @@ begin;
|
||||
|
||||
-- Add new indexes for the create time and update time queries.
|
||||
create index host_plugin_set_create_time_public_id_idx
|
||||
on host_plugin_set (create_time desc, public_id asc);
|
||||
on host_plugin_set (create_time desc, public_id desc);
|
||||
create index host_plugin_set_update_time_public_id_idx
|
||||
on host_plugin_set (update_time desc, public_id asc);
|
||||
on host_plugin_set (update_time desc, public_id desc);
|
||||
|
||||
analyze host_plugin_set;
|
||||
|
||||
-- Add new indexes for the create time and update time queries.
|
||||
create index static_host_set_create_time_public_id_idx
|
||||
on static_host_set (create_time desc, public_id asc);
|
||||
on static_host_set (create_time desc, public_id desc);
|
||||
create index static_host_set_update_time_public_id_idx
|
||||
on static_host_set (update_time desc, public_id asc);
|
||||
on static_host_set (update_time desc, public_id desc);
|
||||
|
||||
analyze static_host_set;
|
||||
|
||||
|
||||
@@ -362,7 +362,7 @@ with host_sets as (
|
||||
attributes
|
||||
from host_plugin_set
|
||||
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 (
|
||||
@@ -407,7 +407,7 @@ final as (
|
||||
)
|
||||
select *
|
||||
from final
|
||||
order by create_time desc, public_id asc;
|
||||
order by create_time desc, public_id desc;
|
||||
`
|
||||
|
||||
listSetsPageTemplate = `
|
||||
@@ -426,7 +426,7 @@ with host_sets as (
|
||||
from host_plugin_set
|
||||
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 (
|
||||
@@ -471,7 +471,7 @@ final as (
|
||||
)
|
||||
select *
|
||||
from final
|
||||
order by create_time desc, public_id asc;
|
||||
order by create_time desc, public_id desc;
|
||||
`
|
||||
|
||||
listSetsRefreshTemplate = `
|
||||
@@ -490,7 +490,7 @@ with host_sets as (
|
||||
from host_plugin_set
|
||||
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 (
|
||||
@@ -535,7 +535,7 @@ final as (
|
||||
)
|
||||
select *
|
||||
from final
|
||||
order by update_time desc, public_id asc;
|
||||
order by update_time desc, public_id desc;
|
||||
`
|
||||
|
||||
listSetsRefreshPageTemplate = `
|
||||
@@ -555,7 +555,7 @@ with host_sets 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 (
|
||||
@@ -600,6 +600,6 @@ final as (
|
||||
)
|
||||
select *
|
||||
from final
|
||||
order by update_time desc, public_id asc;
|
||||
order by update_time desc, public_id desc;
|
||||
`
|
||||
)
|
||||
@@ -267,7 +267,7 @@ func (r *Repository) listSets(ctx context.Context, catalogId string, opt ...Opti
|
||||
}
|
||||
whereClause := "catalog_id = @catalog_id"
|
||||
args := []any{sql.Named("catalog_id", catalogId)}
|
||||
order := "create_time desc, public_id asc"
|
||||
order := "create_time desc, public_id desc"
|
||||
if opts.withStartPageAfterItem != nil {
|
||||
args = append(args,
|
||||
sql.Named("last_item_create_time", opts.withStartPageAfterItem.GetCreateTime()),
|
||||
@@ -301,7 +301,7 @@ func (r *Repository) listSetsRefresh(ctx context.Context, catalogId string, upda
|
||||
sql.Named("catalog_id", catalogId),
|
||||
sql.Named("updated_after_time", updatedAfter),
|
||||
}
|
||||
order := "update_time desc, public_id asc"
|
||||
order := "update_time desc, public_id desc"
|
||||
if opts.withStartPageAfterItem != nil {
|
||||
args = append(args,
|
||||
sql.Named("last_item_update_time", opts.withStartPageAfterItem.GetUpdateTime()),
|
||||
|
||||
Reference in new issue
Block a user