api: micro-second resolution for repo pagination

Lists of repositories are sorted and paginated based on their "updated"
timestamp. However, fractional seconds are discarded. This can cause
issues with repositories that have been updated in the same second (e.g.
by running a script).

This commit leverages the micro-second resolution of the timestamp in
postgres to make this case not impossible, yet highly unlikely.
This commit is contained in:
Conrad Hoffmann 2023-08-09 21:09:47 +02:00 committed by Drew DeVault
parent 490163fcd1
commit a063090a89
1 changed files with 2 additions and 2 deletions

View File

@ -103,7 +103,7 @@ func (r *Repository) QueryWithCursor(ctx context.Context,
if cur.Next != "" {
ts, _ := strconv.ParseInt(cur.Next, 10, 64)
updated := time.Unix(ts, 0)
updated := time.UnixMicro(ts)
q = q.Where(database.WithAlias(r.alias, "updated")+"<= ?", updated)
}
q = q.
@ -127,7 +127,7 @@ func (r *Repository) QueryWithCursor(ctx context.Context,
if len(repos) > cur.Count {
cur = &model.Cursor{
Count: cur.Count,
Next: strconv.FormatInt(repos[len(repos)-1].Updated.Unix(), 10),
Next: strconv.FormatInt(repos[len(repos)-1].Updated.UnixMicro(), 10),
Search: cur.Search,
}
repos = repos[:cur.Count]