1
0
Fork 1
mirror of https://github.com/0x2E/fusion.git synced 2025-06-08 05:27:15 +09:00

fix: item list order

This commit is contained in:
rook1e 2024-03-16 23:59:05 +08:00
parent d684247b42
commit 8f08cbb22d
No known key found for this signature in database
GPG key ID: C63289D731719BC0
4 changed files with 12 additions and 6 deletions

View file

@ -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) {

View file

@ -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

View file

@ -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

View file

@ -26,6 +26,8 @@ type Puller struct {
itemRepo ItemRepo
}
// TODO: cache favicon
func NewPuller(feedRepo FeedRepo, itemRepo ItemRepo) *Puller {
return &Puller{
feedRepo: feedRepo,