From 54a48b58d70eff83dd433cfd86aab60bc885ee7d Mon Sep 17 00:00:00 2001 From: johnnyjoy Date: Wed, 5 Feb 2025 20:48:27 +0800 Subject: [PATCH] chore: remove random field --- store/db/mysql/memo.go | 4 ---- store/db/mysql/user.go | 5 ----- store/db/postgres/memo.go | 4 ---- store/db/postgres/user.go | 5 ----- store/db/sqlite/memo.go | 4 ---- store/db/sqlite/user.go | 5 ----- store/memo.go | 1 - store/user.go | 3 --- 8 files changed, 31 deletions(-) diff --git a/store/db/mysql/memo.go b/store/db/mysql/memo.go index 271fe0c9..caca7554 100644 --- a/store/db/mysql/memo.go +++ b/store/db/mysql/memo.go @@ -145,10 +145,6 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo orders = append(orders, "`created_ts` "+order) } orders = append(orders, "`id` "+order) - if find.Random { - orders = append(orders, "RAND()") - } - fields := []string{ "`memo`.`id` AS `id`", "`memo`.`uid` AS `uid`", diff --git a/store/db/mysql/user.go b/store/db/mysql/user.go index 1f9c4cf6..9bf2d964 100644 --- a/store/db/mysql/user.go +++ b/store/db/mysql/user.go @@ -3,7 +3,6 @@ package mysql import ( "context" "fmt" - "slices" "strings" "github.com/pkg/errors" @@ -99,10 +98,6 @@ func (d *DB) ListUsers(ctx context.Context, find *store.FindUser) ([]*store.User } orderBy := []string{"`created_ts` DESC", "`row_status` DESC"} - if find.Random { - orderBy = slices.Concat([]string{"RAND()"}, orderBy) - } - query := "SELECT `id`, `username`, `role`, `email`, `nickname`, `password_hash`, `avatar_url`, `description`, UNIX_TIMESTAMP(`created_ts`), UNIX_TIMESTAMP(`updated_ts`), `row_status` FROM `user` WHERE " + strings.Join(where, " AND ") + " ORDER BY " + strings.Join(orderBy, ", ") if v := find.Limit; v != nil { query += fmt.Sprintf(" LIMIT %d", *v) diff --git a/store/db/postgres/memo.go b/store/db/postgres/memo.go index 104c8a04..4dbb399d 100644 --- a/store/db/postgres/memo.go +++ b/store/db/postgres/memo.go @@ -137,10 +137,6 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo orders = append(orders, "created_ts "+order) } orders = append(orders, "id "+order) - if find.Random { - orders = append(orders, "RAND()") - } - fields := []string{ `memo.id AS id`, `memo.uid AS uid`, diff --git a/store/db/postgres/user.go b/store/db/postgres/user.go index 13e2890c..2bdf6f16 100644 --- a/store/db/postgres/user.go +++ b/store/db/postgres/user.go @@ -3,7 +3,6 @@ package postgres import ( "context" "fmt" - "slices" "strings" "github.com/usememos/memos/store" @@ -101,10 +100,6 @@ func (d *DB) ListUsers(ctx context.Context, find *store.FindUser) ([]*store.User } orderBy := []string{"created_ts DESC", "row_status DESC"} - if find.Random { - orderBy = slices.Concat([]string{"RANDOM()"}, orderBy) - } - query := ` SELECT id, diff --git a/store/db/sqlite/memo.go b/store/db/sqlite/memo.go index a66d7c00..a40a4890 100644 --- a/store/db/sqlite/memo.go +++ b/store/db/sqlite/memo.go @@ -137,10 +137,6 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo orderBy = append(orderBy, "`created_ts` "+order) } orderBy = append(orderBy, "`id` "+order) - if find.Random { - orderBy = []string{"RANDOM()"} - } - fields := []string{ "`memo`.`id` AS `id`", "`memo`.`uid` AS `uid`", diff --git a/store/db/sqlite/user.go b/store/db/sqlite/user.go index 7efb690e..6c885fd7 100644 --- a/store/db/sqlite/user.go +++ b/store/db/sqlite/user.go @@ -3,7 +3,6 @@ package sqlite import ( "context" "fmt" - "slices" "strings" "github.com/usememos/memos/store" @@ -102,10 +101,6 @@ func (d *DB) ListUsers(ctx context.Context, find *store.FindUser) ([]*store.User } orderBy := []string{"created_ts DESC", "row_status DESC"} - if find.Random { - orderBy = slices.Concat([]string{"RANDOM()"}, orderBy) - } - query := ` SELECT id, diff --git a/store/memo.go b/store/memo.go index 58172fa2..79ed72c8 100644 --- a/store/memo.go +++ b/store/memo.go @@ -73,7 +73,6 @@ type FindMemo struct { PayloadFind *FindMemoPayload ExcludeContent bool ExcludeComments bool - Random bool Filter *string // Pagination diff --git a/store/user.go b/store/user.go index e61d876e..8b5c0fd3 100644 --- a/store/user.go +++ b/store/user.go @@ -83,9 +83,6 @@ type FindUser struct { Email *string Nickname *string - // Random and limit are used in list users. - // Whether to return random users. - Random bool // The maximum number of users to return. Limit *int }