api: images list now always grouped by device then subreddit after sorting
This commit is contained in:
parent
28ddbd3bee
commit
0fec03adbc
|
@ -50,9 +50,22 @@ type ImageListRequest struct {
|
||||||
// - Author's url
|
// - Author's url
|
||||||
var imagesFTSBM25 = fmt.Sprintf("bm25(%s, 25, 20, 10, 5, 3, 3)", ImagesFts5.TableName())
|
var imagesFTSBM25 = fmt.Sprintf("bm25(%s, 25, 20, 10, 5, 3, 3)", ImagesFts5.TableName())
|
||||||
|
|
||||||
func (request ImageListRequest) Statement() SelectStatement {
|
func (request ImageListRequest) Statement() Statement {
|
||||||
// TODO: Change top level select query to WITH query
|
queriedImages := CTE("queried_images")
|
||||||
// so the result can be sorted by Devices and Subreddits.
|
|
||||||
|
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()
|
cond := request.WhereExpression()
|
||||||
from := Images
|
from := Images
|
||||||
|
|
||||||
|
@ -120,6 +133,8 @@ func (request ImageListRequest) WhereExpression() BoolExpression {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ImageList list images by request.
|
// 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) {
|
func (api *API) ImageList(ctx context.Context, request ImageListRequest) (images []model.Images, err error) {
|
||||||
ctx, span := tracer.Start(ctx, "ImageList")
|
ctx, span := tracer.Start(ctx, "ImageList")
|
||||||
defer func() { telemetry.EndWithStatus(span, err) }()
|
defer func() { telemetry.EndWithStatus(span, err) }()
|
||||||
|
|
Loading…
Reference in a new issue