Просмотр исходного кода

fix(storage): look up categories by title case-insensitively

CategoryByTitle matched titles exactly, while CategoryTitleExists and
the category validators compare titles case-insensitively.

With a "News" category, a Google Reader client using the "news" label
passed the existence check but the lookup returned nothing, so
subscribing or moving a feed failed with "category not found" and
marking the label as read returned a 404. The OPML import created a
duplicate "news" category instead of reusing "News".

The lookup is now case-insensitive. When several categories differ
only by case, an exact match is preferred, then the oldest category.
Frédéric Guillot 17 часов назад
Родитель
Сommit
faecfa2fac
1 измененных файлов с 2 добавлено и 2 удалено
  1. 2 2
      internal/storage/category.go

+ 2 - 2
internal/storage/category.go

@@ -79,11 +79,11 @@ func (s *Storage) FirstCategory(userID int64) (*model.Category, error) {
 	}
 }
 
-// CategoryByTitle finds a category by the title.
+// CategoryByTitle finds a category by its case-insensitive title, preferring an exact match.
 func (s *Storage) CategoryByTitle(userID int64, title string) (*model.Category, error) {
 	var category model.Category
 
-	query := `SELECT id, user_id, title, hide_globally FROM categories WHERE user_id=$1 AND title=$2`
+	query := `SELECT id, user_id, title, hide_globally FROM categories WHERE user_id=$1 AND lower(title)=lower($2) ORDER BY title=$2 DESC, id ASC LIMIT 1`
 	err := s.db.QueryRow(query, userID, title).Scan(&category.ID, &category.UserID, &category.Title, &category.HideGlobally)
 
 	switch {