chore: add explore sidebar

This commit is contained in:
Steven
2024-03-29 00:01:45 +08:00
parent 192ee7acc0
commit 90679cc33a
17 changed files with 210 additions and 32 deletions

View File

@@ -2,6 +2,8 @@ package sqlite
import (
"context"
"fmt"
"slices"
"strings"
"github.com/usememos/memos/store"
@@ -99,6 +101,11 @@ func (d *DB) ListUsers(ctx context.Context, find *store.FindUser) ([]*store.User
where, args = append(where, "nickname = ?"), append(args, *v)
}
orderBy := []string{"created_ts DESC", "row_status DESC"}
if find.Random {
orderBy = slices.Concat([]string{"RANDOM()"}, orderBy)
}
query := `
SELECT
id,
@@ -113,9 +120,11 @@ func (d *DB) ListUsers(ctx context.Context, find *store.FindUser) ([]*store.User
updated_ts,
row_status
FROM user
WHERE ` + strings.Join(where, " AND ") + `
ORDER BY created_ts DESC, row_status DESC
`
WHERE ` + strings.Join(where, " AND ") + ` ORDER BY ` + strings.Join(orderBy, ", ")
if v := find.Limit; v != nil {
query += fmt.Sprintf(" LIMIT %d", *v)
}
rows, err := d.db.QueryContext(ctx, query, args...)
if err != nil {
return nil, err