diff --git a/frontend/src/lib/api/item.ts b/frontend/src/lib/api/item.ts index 6ac3299..5ac7c09 100644 --- a/frontend/src/lib/api/item.ts +++ b/frontend/src/lib/api/item.ts @@ -15,14 +15,11 @@ export async function listItems(options?: ListFilter) { // trip undefinded fields: https://github.com/sindresorhus/ky/issues/293 options = JSON.parse(JSON.stringify(options)); } - const data = await api + return await api .get('items', { searchParams: options }) .json<{ total: number; items: Item[] }>(); - - data.items.sort((a, b) => new Date(b.pub_date).getTime() - new Date(a.pub_date).getTime()); - return data; } export function parseURLtoFilter(params: URLSearchParams) { diff --git a/model/feed.go b/model/feed.go index 9c566cf..4e60a62 100644 --- a/model/feed.go +++ b/model/feed.go @@ -13,7 +13,7 @@ type Feed struct { DeletedAt soft_delete.DeletedAt Name *string `gorm:"name;not null"` - Link *string `gorm:"link;not null"` + Link *string `gorm:"link;not null"` // FIX: unique index? // LastBuild is the last time the content of the feed changed LastBuild *time.Time `gorm:"last_build"` // Failure is the reason of failure. If it is not null or empty, the fetch processor diff --git a/repo/item.go b/repo/item.go index 7b4877a..ca9bcf8 100644 --- a/repo/item.go +++ b/repo/item.go @@ -1,6 +1,8 @@ package repo import ( + "time" + "github.com/0x2e/fusion/model" "gorm.io/gorm" @@ -46,7 +48,7 @@ func (i Item) List(filter ItemFilter, page, pageSize int) ([]*model.Item, int, e return nil, 0, err } - err = db.Joins("Feed").Order("items.pub_date desc"). + err = db.Joins("Feed").Order("items.created_at desc, items.pub_date desc"). Offset((page - 1) * pageSize).Limit(pageSize).Find(&res).Error return res, int(total), err } @@ -59,6 +61,11 @@ func (i Item) Get(id uint) (*model.Item, error) { func (i Item) Creates(items []*model.Item) error { // limit batchSize to fix 'too many SQL variable' error + now := time.Now() + for _, i := range items { + i.CreatedAt = now + i.UpdatedAt = now + } return i.db.Clauses(clause.OnConflict{ DoNothing: true, }).CreateInBatches(items, 5).Error diff --git a/service/pull/pull.go b/service/pull/pull.go index 0e37176..98f449d 100644 --- a/service/pull/pull.go +++ b/service/pull/pull.go @@ -26,6 +26,8 @@ type Puller struct { itemRepo ItemRepo } +// TODO: cache favicon + func NewPuller(feedRepo FeedRepo, itemRepo ItemRepo) *Puller { return &Puller{ feedRepo: feedRepo,