8000 [pull] main from miniflux:main by pull[bot] · Pull Request #304 · suhaoGe/miniflux · GitHub
[go: up one dir, main page]

Skip to content
8000
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions internal/database/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -1510,4 +1510,19 @@ var migrations = [...]func(tx *sql.Tx) error{
`)
return err
},
func(tx *sql.Tx) (err error) {
// entries_feed_idx is redundant: the unique constraint
// entries_feed_id_hash_key(feed_id, hash) and the explicit
// entries_feed_id_status_hash_idx(feed_id, status, hash) both
// cover feed_id-leading lookups, including FK cascade deletes.
//
// entries_user_status_idx is redundant: five three-column indexes
// share the same (user_id, status) prefix and serve every query
// that the two-column index could.
_, err = tx.Exec(`
DROP INDEX IF EXISTS entries_feed_idx;
DROP INDEX IF EXISTS entries_user_status_idx;
`)
return err
},
}
2 changes: 1 addition & 1 deletion internal/integration/karakeep/karakeep.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (c *Client) attachTags(entryID string) error {
return nil
}

tagItems := make([]tagItem, 0)
tagItems := make([]tagItem, 0, strings.Count(c.tags, ",")+1)
for tag := range strings.SplitSeq(c.tags, ",") {
if trimmedTag := strings.TrimSpace(tag); trimmedTag != "" {
tagItems = append(tagItems, tagItem{TagName: trimmedTag})
Expand Down
4 changes: 2 additions & 2 deletions internal/reader/atom/atom_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (a atomLinks) firstLinkWithRelationAndType(relation string, contentTypes ..
}

func (a atomLinks) findAllLinksWithRelation(relation string) []*AtomLink {
var links []*AtomLink
links := make([]*AtomLink, 0, len(a))

for _, link := range a {
if strings.EqualFold(link.Rel, relation) {
Expand Down Expand Up @@ -137,7 +137,7 @@ type atomCategory struct {
type atomCategories []atomCategory

func (ac atomCategories) CategoryNames() []string {
var categories []string
categories := make([]string, 0, len(ac))

for _, category := range ac {
label := strings.TrimSpace(category.Label)
Expand Down
2 changes: 1 addition & 1 deletion internal/reader/json/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (j *JSONAdapter) BuildFeed(baseURL string) *model.Feed {
itemAuthors = append(itemAuthors, item.Authors...)
itemAuthors = append(itemAuthors, item.Author, j.jsonFeed.Author)

var authorNames []string
var authorNames = make([]string, 0, len(itemAuthors))
for _, author := range itemAuthors {
authorName := strings.TrimSpace(author.Name)
if authorName != "" {
Expand Down
3 changes: 2 additions & 1 deletion internal/storage/entry_pagination_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strconv"
"strings"

"github.com/lib/pq"
"miniflux.app/v2/internal/model"
)

Expand Down Expand Up @@ -192,7 +193,7 @@ func NewEntryPaginationBuilder(store *Storage, userID, entryID int64, order, dir
args: []any{userID},
conditions: []string{"e.user_id = $1"},
entryID: entryID,
order: order,
order: pq.QuoteIdentifier(order),
direction: direction,
}
}
15 changes: 10 additions & 5 deletions internal/storage/entry_query_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ func (e *EntryQueryBuilder) WithSearchQuery(query string) *EntryQueryBuilder {
e.args = append(e.args, query)

// 0.0000001 = 0.1 / (seconds_in_a_day)
e.WithSorting(
fmt.Sprintf("ts_rank(document_vectors, plainto_tsquery($%d)) - extract (epoch from now() - published_at)::float * 0.0000001", nArgs),
"DESC",

e.sortExpressions = append(e.sortExpressions,
fmt.Sprintf("ts_rank(document_vectors, plainto_tsquery($%d)) - extract (epoch from now() - published_at)::float * 0.0000001 DESC", nArgs),
)
}
return e
Expand Down Expand Up @@ -209,7 +209,13 @@ func (e *EntryQueryBuilder) WithShareCodeNotEmpty() *EntryQueryBuilder {

// WithSorting add a sort expression.
func (e *EntryQueryBuilder) WithSorting(column, direction string) *EntryQueryBuilder {
e.sortExpressions = append(e.sortExpressions, column+" "+direction)
switch {
case strings.EqualFold(direction, "ASC"):
e.sortExpressions = append(e.sortExpressions, pq.QuoteIdentifier(column)+" ASC")
case strings.EqualFold(direction, "DESC"):
e.sortExpressions = append(e.sortExpressions, pq.QuoteIdentifier(column)+" DESC")
}

return e
}

Expand Down Expand Up @@ -410,7 +416,6 @@ func (e *EntryQueryBuilder) fetchEntries(withCount bool) (model.Entries, int, er
}

err := rows.Scan(dest...)

if err != nil {
return nil, 0, fmt.Errorf("store: unable to fetch entry row: %v", err)
}
Expand Down
9 changes: 8 additions & 1 deletion internal/storage/feed_query_builder.go
< 8BD0 td class="blob-code blob-code-inner blob-code-hunk">@@ -9,6 +9,7 @@ import (
Original file line number Diff line number Diff line change
Expand Up
"strconv"
"strings"

"github.com/lib/pq"
"miniflux.app/v2/internal/model"
"miniflux.app/v2/internal/timezone"
)
Expand Down Expand Up @@ -67,7 +68,13 @@ func (f *feedQueryBuilder) WithCounters() *feedQueryBuilder {

// WithSorting add a sort expression.
func (f *feedQueryBuilder) WithSorting(column, direction string) *feedQueryBuilder {
f.sortExpressions = append(f.sortExpressions, column+" "+direction)
switch {
case strings.EqualFold(direction, "ASC"):
f.sortExpressions = append(f.sortExpressions, pq.QuoteIdentifier(column)+" ASC")
case strings.EqualFold(direction, "DESC"):
f.sortExpressions = append(f.sortExpressions, pq.QuoteIdentifier(column)+" DESC")
}

return f
}

Expand Down
Loading
0