refactor: improve search user collections logic to handle optional keyword

This commit is contained in:
2025-07-31 11:01:49 +08:00
parent 470324221d
commit 40fb3a93b6
3 changed files with 9 additions and 5 deletions

View File

@@ -181,7 +181,11 @@ func SearchUserCollections(uid uint, keyword string, excludedRID uint) ([]*model
var collections []*model.Collection
query := db.Model(&model.Collection{}).
Where("user_id = ? AND title LIKE ?", uid, "%"+keyword+"%")
Where("user_id = ?", uid)
if keyword != "" {
query = query.Where("title LIKE ?", "%"+keyword+"%")
}
if excludedRID > 0 {
// Use LEFT JOIN with IS NULL for better performance