diff --git a/internal/database/migrations.go b/internal/database/migrations.go index cfc1159d..d40e5d2f 100644 --- a/internal/database/migrations.go +++ b/internal/database/migrations.go @@ -876,4 +876,10 @@ var migrations = []func(tx *sql.Tx) error{ _, err = tx.Exec(sql) return err }, + func(tx *sql.Tx) (err error) { + // the WHERE part speed-up the request a lot + sql := `UPDATE entries SET tags = array_remove(tags, '') WHERE '' = ANY(tags);` + _, err = tx.Exec(sql) + return err + }, } diff --git a/internal/storage/entry.go b/internal/storage/entry.go index c9037094..1a7cc6d7 100644 --- a/internal/storage/entry.go +++ b/internal/storage/entry.go @@ -9,6 +9,7 @@ import ( "fmt" "log/slog" "slices" + "strings" "time" "miniflux.app/v2/internal/crypto" @@ -139,7 +140,7 @@ func (s *Storage) createEntry(tx *sql.Tx, entry *model.Entry) error { entry.UserID, entry.FeedID, entry.ReadingTime, - pq.Array(removeDuplicates(entry.Tags)), + pq.Array(removeEmpty(removeDuplicates(entry.Tags))), ).Scan( &entry.ID, &entry.Status, @@ -195,7 +196,7 @@ func (s *Storage) updateEntry(tx *sql.Tx, entry *model.Entry) error { entry.UserID, entry.FeedID, entry.Hash, - pq.Array(removeDuplicates(entry.Tags)), + pq.Array(removeEmpty(removeDuplicates(entry.Tags))), ).Scan(&entry.ID) if err != nil { @@ -620,3 +621,13 @@ func removeDuplicates(l []string) []string { slices.Sort(l) return slices.Compact(l) } + +func removeEmpty(l []string) []string { + var finalSlice []string + for _, item := range l { + if strings.TrimSpace(item) != "" { + finalSlice = append(finalSlice, item) + } + } + return finalSlice +}