Skip to content

Commit 5854c79

Browse files
committed
Speed-up dashboard for mysql by using index hints
1 parent 9e64ffc commit 5854c79

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

models/action.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,10 @@ func GetFeeds(opts GetFeedsOptions) ([]*Action, error) {
337337

338338
actions := make([]*Action, 0, setting.UI.FeedPagingNum)
339339

340-
if err := db.GetEngine(db.DefaultContext).Limit(setting.UI.FeedPagingNum).Desc("created_unix").Where(cond).Find(&actions); err != nil {
340+
sqlCond, _ := builder.ToBoundSQL(cond)
341+
sqlCond = strings.ReplaceAll(sqlCond, "visibility IN (private,limited)", "visibility IN (2,1)")
342+
sqlCond = strings.ReplaceAll(sqlCond, "visibility IN (private)", "visibility IN (2)")
343+
if err := db.GetEngine(db.DefaultContext).SQL("SELECT `id`, `user_id`, `op_type`, `act_user_id`, `repo_id`, `comment_id`, `is_deleted`, `ref_name`, `is_private`, `content`, `created_unix` FROM `action` use INDEX(IDX_action_created_unix) WHERE " + sqlCond + " ORDER BY `created_unix` DESC LIMIT " + strconv.Itoa(setting.UI.FeedPagingNum)).Find(&actions); err != nil {
341344
return nil, fmt.Errorf("Find: %v", err)
342345
}
343346

0 commit comments

Comments
 (0)