internal/credential: 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 fc9b26efa7
commit 6238a533b0
6 files changed
+30 -30

No files matched your search

+8 -8
View File
@@ -26,7 +26,7 @@ with stores as (
select public_id
from credential_store
where %s -- search condition for project IDs is constructed
order by create_time desc, public_id asc
order by create_time desc, public_id desc
limit %d
),
vault_stores as (
@@ -102,7 +102,7 @@ final as (
)
select *
from final
order by create_time desc, public_id asc;
order by create_time desc, public_id desc;
`
listStoresPageTemplate = `
@@ -111,7 +111,7 @@ with stores as (
from credential_store
where (create_time, public_id) < (@last_item_create_time, @last_item_id) and
%s -- search condition for project IDs is constructed
order by create_time desc, public_id asc
order by create_time desc, public_id desc
limit %d
),
vault_stores as (
@@ -187,7 +187,7 @@ final as (
)
select *
from final
order by create_time desc, public_id asc;
order by create_time desc, public_id desc;
`
listStoresRefreshTemplate = `
@@ -196,7 +196,7 @@ with stores as (
from credential_store
where update_time > @updated_after_time and
%s -- search condition for project IDs is constructed
order by update_time desc, public_id asc
order by update_time desc, public_id desc
limit %d
),
vault_stores as (
@@ -272,7 +272,7 @@ final as (
)
select *
from final
order by update_time desc, public_id asc;
order by update_time desc, public_id desc;
`
listStoresRefreshPageTemplate = `
@@ -282,7 +282,7 @@ with stores as (
where update_time > @updated_after_time and
(update_time, public_id) < (@last_item_update_time, @last_item_id) and
%s -- search condition for project IDs is constructed
order by update_time desc, public_id asc
order by update_time desc, public_id desc
limit %d
),
vault_stores as (
@@ -358,6 +358,6 @@ final as (
)
select *
from final
order by update_time desc, public_id asc;
order by update_time desc, public_id desc;
`
)
+8 -8
View File
@@ -56,7 +56,7 @@ with credentials as (
select public_id
from credential_static
where store_id = @store_id
order by create_time desc, public_id asc
order by create_time desc, public_id desc
limit %d
),
json_creds as (
@@ -122,7 +122,7 @@ final as (
)
select *
from final
order by create_time desc, public_id asc;
order by create_time desc, public_id desc;
`
listCredentialsPageTemplate = `
@@ -131,7 +131,7 @@ with credentials as (
from credential_static
where store_id = @store_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
),
json_creds 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;
`
listCredentialsRefreshTemplate = `
@@ -206,7 +206,7 @@ with credentials as (
from credential_static
where store_id = @store_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
),
json_creds as (
@@ -272,7 +272,7 @@ final as (
)
select *
from final
order by update_time desc, public_id asc;
order by update_time desc, public_id desc;
`
listCredentialsRefreshPageTemplate = `
@@ -282,7 +282,7 @@ with credentials as (
where store_id = @store_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
),
json_creds as (
@@ -348,6 +348,6 @@ final as (
)
select *
from final
order by update_time desc, public_id asc;
order by update_time desc, public_id desc;
`
)
+8 -8
View File
@@ -204,7 +204,7 @@ with libraries as (
select public_id
from credential_library
where store_id = @store_id
order by create_time desc, public_id asc
order by create_time desc, public_id desc
limit %d
),
generic_libs as (
@@ -266,7 +266,7 @@ final as (
)
select *
from final
order by create_time desc, public_id asc;
order by create_time desc, public_id desc;
`
listLibrariesPageTemplate = `
@@ -275,7 +275,7 @@ with libraries as (
from credential_library
where store_id = @store_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
),
generic_libs as (
@@ -337,7 +337,7 @@ final as (
)
select *
from final
order by create_time desc, public_id asc;
order by create_time desc, public_id desc;
`
listLibrariesRefreshTemplate = `
@@ -346,7 +346,7 @@ with libraries as (
from credential_library
where store_id = @store_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
),
generic_libs as (
@@ -408,7 +408,7 @@ final as (
)
select *
from final
order by update_time desc, public_id asc;
order by update_time desc, public_id desc;
`
listLibrariesRefreshPageTemplate = `
@@ -418,7 +418,7 @@ with libraries as (
where store_id = @store_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
),
generic_libs as (
@@ -480,6 +480,6 @@ final as (
)
select *
from final
order by update_time desc, public_id asc;
order by update_time desc, public_id desc;
`
)
@@ -60,9 +60,9 @@ begin;
-- Add new indexes for the create and update time queries.
create index credential_static_create_time_public_id_idx
on credential_static (create_time desc, public_id asc);
on credential_static (create_time desc, public_id desc);
create index credential_static_update_time_public_id_idx
on credential_static (update_time desc, public_id asc);
on credential_static (update_time desc, public_id desc);
analyze credential_static;
@@ -54,9 +54,9 @@ begin;
-- Add new indexes for the create and update time queries.
create index credential_library_create_time_public_id_idx
on credential_library (create_time desc, public_id asc);
on credential_library (create_time desc, public_id desc);
create index credential_library_update_time_public_id_idx
on credential_library (update_time desc, public_id asc);
on credential_library (update_time desc, public_id desc);
analyze credential_library;
@@ -50,9 +50,9 @@ begin;
-- Add new indexes for the create and update time queries.
create index credential_store_create_time_public_id_idx
on credential_store (create_time desc, public_id asc);
on credential_store (create_time desc, public_id desc);
create index credential_store_update_time_public_id_idx
on credential_store (update_time desc, public_id asc);
on credential_store (update_time desc, public_id desc);
analyze credential_store;