feat(pagination): paginate activity and progress lists

This commit is contained in:
2026-05-02 15:32:10 -04:00
parent 75c872264f
commit 00faf9cea8
15 changed files with 341 additions and 59 deletions

View File

@@ -396,3 +396,40 @@ SET
isbn10 = COALESCE(excluded.isbn10, isbn10),
isbn13 = COALESCE(excluded.isbn13, isbn13)
RETURNING *;
-- name: GetDocumentsWithStatsCount :one
SELECT COUNT(*) AS count
FROM documents AS docs
WHERE
(docs.id = sqlc.narg('id') OR $id IS NULL)
AND (docs.deleted = sqlc.narg(deleted) OR $deleted IS NULL)
AND (
(
docs.title LIKE sqlc.narg('query') OR
docs.author LIKE $query
) OR $query IS NULL
);
-- name: GetProgressCount :one
SELECT COUNT(*) AS count
FROM document_progress AS progress
WHERE
progress.user_id = $user_id
AND (
(
CAST($doc_filter AS BOOLEAN) = TRUE
AND document_id = $document_id
) OR $doc_filter = FALSE
);
-- name: GetActivityCount :one
SELECT COUNT(*) AS count
FROM activity
WHERE
activity.user_id = $user_id
AND (
(
CAST($doc_filter AS BOOLEAN) = TRUE
AND document_id = $document_id
) OR $doc_filter = FALSE
);

View File

@@ -1,6 +1,6 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.29.0
// sqlc v1.31.1
// source: query.sql
package database
@@ -264,6 +264,32 @@ func (q *Queries) GetActivity(ctx context.Context, arg GetActivityParams) ([]Get
return items, nil
}
const getActivityCount = `-- name: GetActivityCount :one
SELECT COUNT(*) AS count
FROM activity
WHERE
activity.user_id = ?1
AND (
(
CAST(?2 AS BOOLEAN) = TRUE
AND document_id = ?3
) OR ?2 = FALSE
)
`
type GetActivityCountParams struct {
UserID string `json:"user_id"`
DocFilter bool `json:"doc_filter"`
DocumentID string `json:"document_id"`
}
func (q *Queries) GetActivityCount(ctx context.Context, arg GetActivityCountParams) (int64, error) {
row := q.db.QueryRowContext(ctx, getActivityCount, arg.UserID, arg.DocFilter, arg.DocumentID)
var count int64
err := row.Scan(&count)
return count, err
}
const getDailyReadStats = `-- name: GetDailyReadStats :many
WITH RECURSIVE last_30_days AS (
SELECT LOCAL_DATE(STRFTIME('%Y-%m-%dT%H:%M:%SZ', 'now'), timezone) AS date
@@ -734,6 +760,33 @@ func (q *Queries) GetDocumentsWithStats(ctx context.Context, arg GetDocumentsWit
return items, nil
}
const getDocumentsWithStatsCount = `-- name: GetDocumentsWithStatsCount :one
SELECT COUNT(*) AS count
FROM documents AS docs
WHERE
(docs.id = ?1 OR ?1 IS NULL)
AND (docs.deleted = ?2 OR ?2 IS NULL)
AND (
(
docs.title LIKE ?3 OR
docs.author LIKE ?3
) OR ?3 IS NULL
)
`
type GetDocumentsWithStatsCountParams struct {
ID *string `json:"id"`
Deleted *bool `json:"-"`
Query *string `json:"query"`
}
func (q *Queries) GetDocumentsWithStatsCount(ctx context.Context, arg GetDocumentsWithStatsCountParams) (int64, error) {
row := q.db.QueryRowContext(ctx, getDocumentsWithStatsCount, arg.ID, arg.Deleted, arg.Query)
var count int64
err := row.Scan(&count)
return count, err
}
const getLastActivity = `-- name: GetLastActivity :one
SELECT start_time
FROM activity
@@ -897,6 +950,32 @@ func (q *Queries) GetProgress(ctx context.Context, arg GetProgressParams) ([]Get
return items, nil
}
const getProgressCount = `-- name: GetProgressCount :one
SELECT COUNT(*) AS count
FROM document_progress AS progress
WHERE
progress.user_id = ?1
AND (
(
CAST(?2 AS BOOLEAN) = TRUE
AND document_id = ?3
) OR ?2 = FALSE
)
`
type GetProgressCountParams struct {
UserID string `json:"user_id"`
DocFilter bool `json:"doc_filter"`
DocumentID string `json:"document_id"`
}
func (q *Queries) GetProgressCount(ctx context.Context, arg GetProgressCountParams) (int64, error) {
row := q.db.QueryRowContext(ctx, getProgressCount, arg.UserID, arg.DocFilter, arg.DocumentID)
var count int64
err := row.Scan(&count)
return count, err
}
const getUser = `-- name: GetUser :one
SELECT id, pass, auth_hash, admin, timezone, created_at FROM users
WHERE id = ?1 LIMIT 1
@@ -1088,17 +1167,22 @@ WHERE (
AND documents.filepath IS NULL
)
OR (documents.id IS NULL)
OR CAST(?1 AS TEXT) != CAST(?1 AS TEXT)
OR CAST(?2 AS TEXT) != CAST(?2 AS TEXT)
`
type GetWantedDocumentsParams struct {
JsonEach interface{} `json:"json_each"`
DocumentIds string `json:"document_ids"`
}
type GetWantedDocumentsRow struct {
ID string `json:"id"`
WantFile bool `json:"want_file"`
WantMetadata bool `json:"want_metadata"`
}
func (q *Queries) GetWantedDocuments(ctx context.Context, documentIds string) ([]GetWantedDocumentsRow, error) {
rows, err := q.db.QueryContext(ctx, getWantedDocuments, documentIds)
func (q *Queries) GetWantedDocuments(ctx context.Context, arg GetWantedDocumentsParams) ([]GetWantedDocumentsRow, error) {
rows, err := q.db.QueryContext(ctx, getWantedDocuments, arg.JsonEach, arg.DocumentIds)
if err != nil {
return nil, err
}