api: images list now always grouped by device then subreddit after sorting

This commit is contained in:
Tigor Hutasuhut 2024-08-25 16:54:00 +07:00
parent 28ddbd3bee
commit 0fec03adbc

View file

@ -50,9 +50,22 @@ type ImageListRequest struct {
// - Author's url
var imagesFTSBM25 = fmt.Sprintf("bm25(%s, 25, 20, 10, 5, 3, 3)", ImagesFts5.TableName())
func (request ImageListRequest) Statement() SelectStatement {
// TODO: Change top level select query to WITH query
// so the result can be sorted by Devices and Subreddits.
func (request ImageListRequest) Statement() Statement {
queriedImages := CTE("queried_images")
return WITH(
queriedImages.AS(request.SelectStatement()),
)(
SELECT(queriedImages.AllColumns()).
FROM(queriedImages).
ORDER_BY(
Images.Device.ASC(),
Images.Subreddit.ASC(),
),
)
}
func (request ImageListRequest) SelectStatement() SelectStatement {
cond := request.WhereExpression()
from := Images
@ -120,6 +133,8 @@ func (request ImageListRequest) WhereExpression() BoolExpression {
}
// ImageList list images by request.
//
// Results are always grouped by device then grouped by subreddit after sorting.
func (api *API) ImageList(ctx context.Context, request ImageListRequest) (images []model.Images, err error) {
ctx, span := tracer.Start(ctx, "ImageList")
defer func() { telemetry.EndWithStatus(span, err) }()