internal/session: 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.
This commit is contained in:
Johan Brandhorst-Satzkorn committed 2024-01-05 07:43:21 -08:00
1 parent 6238a533b0
commit d4d1efce93
2 files changed
+11 -11

No files matched your search

@@ -5,10 +5,10 @@ begin;
-- Add new indexes for the create time and update time queries.
create index session_create_time_public_id_idx
on session (create_time desc, public_id asc);
on session (create_time desc, public_id desc);
create index session_update_time_public_id_idx
on session (update_time desc, public_id asc);
on session (update_time desc, public_id desc);
analyze session;
commit;
commit;
+8 -8
View File
@@ -429,13 +429,13 @@ with session_ids as (
from session
-- search condition for applying permissions is constructed
where %s
order by create_time desc, public_id asc
order by create_time desc, public_id desc
limit %d
)
select *
from session_list
where session_list.public_id in (select * from session_ids)
order by create_time desc, public_id asc;
order by create_time desc, public_id desc;
`
listSessionsPageTemplate = `
with session_ids as (
@@ -444,13 +444,13 @@ with session_ids as (
where (create_time, public_id) < (@last_item_create_time, @last_item_id)
-- search condition for applying permissions is constructed
and %s
order by create_time desc, public_id asc
order by create_time desc, public_id desc
limit %d
)
select *
from session_list
where session_list.public_id in (select * from session_ids)
order by create_time desc, public_id asc;
order by create_time desc, public_id desc;
`
refreshSessionsTemplate = `
with session_ids as (
@@ -459,13 +459,13 @@ with session_ids as (
where update_time > @updated_after_time
-- search condition for applying permissions is constructed
and %s
order by update_time desc, public_id asc
order by update_time desc, public_id desc
limit %d
)
select *
from session_list
where session_list.public_id in (select * from session_ids)
order by update_time desc, public_id asc;
order by update_time desc, public_id desc;
`
refreshSessionsPageTemplate = `
with session_ids as (
@@ -475,13 +475,13 @@ with session_ids as (
and (update_time, public_id) < (@last_item_update_time, @last_item_id)
-- search condition for applying permissions is constructed
and %s
order by update_time desc, public_id asc
order by update_time desc, public_id desc
limit %d
)
select *
from session_list
where session_list.public_id in (select * from session_ids)
order by update_time desc, public_id asc;
order by update_time desc, public_id desc;
`
estimateCountSessions = `
select reltuples::bigint as estimate from pg_class where oid in ('session'::regclass)