From a8a448330008ce5e0e8a79b391201a0b398574ef Mon Sep 17 00:00:00 2001 From: rafmaster7 Date: Wed, 16 Sep 2026 16:29:58 +0200 Subject: [PATCH] feat: "Most viewed" sort order on the question list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds order=views to the question list (and the linked-questions list): pinned first, then question.view_count DESC, newest first on ties. UI: new entry in QUESTION_ORDER_KEYS, label question.views. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_0181uZ2px83HmPo3HKSEzWQR Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_0181uZ2px83HmPo3HKSEzWQR --- i18n/en_US.yaml | 1 + internal/repo/question/question_repo.go | 4 ++++ internal/schema/question_schema.go | 5 +++-- ui/src/common/interface.ts | 3 ++- ui/src/components/QuestionList/index.tsx | 1 + 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/i18n/en_US.yaml b/i18n/en_US.yaml index 5d1faa3e0..e74a42c4b 100644 --- a/i18n/en_US.yaml +++ b/i18n/en_US.yaml @@ -1630,6 +1630,7 @@ ui: recommend: Recommend score: Score unanswered: Unanswered + views: Most viewed modified: modified answered: answered asked: asked diff --git a/internal/repo/question/question_repo.go b/internal/repo/question/question_repo.go index 3449efb8b..9a1c31b46 100644 --- a/internal/repo/question/question_repo.go +++ b/internal/repo/question/question_repo.go @@ -441,6 +441,8 @@ func (qr *questionRepo) GetQuestionPage(ctx context.Context, page, pageSize int, session.OrderBy("question.pin desc,question.created_at DESC") case "frequent": session.OrderBy("question.pin DESC, question.linked_count DESC, question.updated_at DESC") + case "views": + session.OrderBy("question.pin DESC, question.view_count DESC, question.created_at DESC") } session.GroupBy("question.id") @@ -854,6 +856,8 @@ func (qr *questionRepo) GetQuestionLink(ctx context.Context, page, pageSize int, session.OrderBy("question.pin desc,question.created_at DESC") case "frequent": session.OrderBy("question.pin DESC, question.linked_count DESC, question.updated_at DESC") + case "views": + session.OrderBy("question.pin DESC, question.view_count DESC, question.created_at DESC") } if page > 0 && pageSize > 0 { diff --git a/internal/schema/question_schema.go b/internal/schema/question_schema.go index 4c2313852..07df89b97 100644 --- a/internal/schema/question_schema.go +++ b/internal/schema/question_schema.go @@ -359,6 +359,7 @@ const ( QuestionOrderCondUnanswered = "unanswered" QuestionOrderCondRecommend = "recommend" QuestionOrderCondFrequent = "frequent" + QuestionOrderCondViews = "views" // HotInDays limit max days of the hottest question HotInDays = 90 @@ -368,7 +369,7 @@ const ( type QuestionPageReq struct { Page int `validate:"omitempty,min=1" form:"page"` PageSize int `validate:"omitempty,min=1" form:"page_size"` - OrderCond string `validate:"omitempty,oneof=newest active hot score unanswered recommend frequent" form:"order"` + OrderCond string `validate:"omitempty,oneof=newest active hot score unanswered recommend frequent views" form:"order"` Tag string `validate:"omitempty,gt=0,lte=100" form:"tag"` Username string `validate:"omitempty,gt=0,lte=100" form:"username"` InDays int `validate:"omitempty,min=1" form:"in_days"` @@ -517,7 +518,7 @@ type GetQuestionLinkReq struct { Page int `validate:"omitempty,min=1" form:"page"` PageSize int `validate:"omitempty,min=1,max=100" form:"page_size"` QuestionID string `validate:"required" form:"question_id"` - OrderCond string `validate:"omitempty,oneof=newest active hot score unanswered recommend frequent" form:"order"` + OrderCond string `validate:"omitempty,oneof=newest active hot score unanswered recommend frequent views" form:"order"` InDays int `validate:"omitempty,min=1" form:"in_days"` LoginUserID string `json:"-"` diff --git a/ui/src/common/interface.ts b/ui/src/common/interface.ts index 8ab714230..9f25ac8fb 100644 --- a/ui/src/common/interface.ts +++ b/ui/src/common/interface.ts @@ -302,7 +302,8 @@ export type QuestionOrderBy = | 'hot' | 'score' | 'unanswered' - | 'frequent'; + | 'frequent' + | 'views'; export interface QueryQuestionsReq extends Paging { order: QuestionOrderBy; diff --git a/ui/src/components/QuestionList/index.tsx b/ui/src/components/QuestionList/index.tsx index 3d770dbe5..63df2f8e0 100644 --- a/ui/src/components/QuestionList/index.tsx +++ b/ui/src/components/QuestionList/index.tsx @@ -47,6 +47,7 @@ export const QUESTION_ORDER_KEYS: Type.QuestionOrderBy[] = [ 'recommend', 'frequent', 'score', + 'views', ]; interface Props { source: 'questions' | 'tag' | 'linked';