forked from 0x2E/fusion
fix: item list order
This commit is contained in:
parent
d684247b42
commit
8f08cbb22d
4 changed files with 12 additions and 6 deletions
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -26,6 +26,8 @@ type Puller struct {
|
|||
itemRepo ItemRepo
|
||||
}
|
||||
|
||||
// TODO: cache favicon
|
||||
|
||||
func NewPuller(feedRepo FeedRepo, itemRepo ItemRepo) *Puller {
|
||||
return &Puller{
|
||||
feedRepo: feedRepo,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue