mirror of
https://github.com/nkanaev/yarr.git
synced 2026-04-30 14:27:45 +00:00
add item.last_arrived field
This commit is contained in:
@@ -135,14 +135,15 @@ func (s *Storage) CreateItems(items []Item) bool {
|
||||
insert into items (
|
||||
guid, feed_id, title, link, date,
|
||||
content, media_links,
|
||||
date_arrived, status
|
||||
date_arrived, last_arrived, status
|
||||
)
|
||||
values (
|
||||
:guid, :feed_id, :title, :link, strftime('%Y-%m-%d %H:%M:%f', :date),
|
||||
:content, :media_links,
|
||||
:date_arrived, :status
|
||||
:date_arrived, :last_arrived, :status
|
||||
)
|
||||
on conflict (feed_id, guid) do nothing`,
|
||||
on conflict (feed_id, guid) do update set
|
||||
last_arrived = :last_arrived`,
|
||||
sql.Named("guid", item.GUID),
|
||||
sql.Named("feed_id", item.FeedId),
|
||||
sql.Named("title", item.Title),
|
||||
@@ -151,6 +152,7 @@ func (s *Storage) CreateItems(items []Item) bool {
|
||||
sql.Named("content", item.Content),
|
||||
sql.Named("media_links", item.MediaLinks),
|
||||
sql.Named("date_arrived", now),
|
||||
sql.Named("last_arrived", now),
|
||||
sql.Named("status", UNREAD),
|
||||
)
|
||||
if err != nil {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"reflect"
|
||||
"strconv"
|
||||
"testing"
|
||||
"testing/synctest"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -374,3 +375,42 @@ func TestDeleteOldItems(t *testing.T) {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateItemsLastArrived(t *testing.T) {
|
||||
synctest.Test(t, func(t *testing.T) {
|
||||
db := testDB()
|
||||
defer db.db.Close()
|
||||
feed := db.CreateFeed("test feed", "", "", "http://example.com/feed", nil)
|
||||
|
||||
item := Item{
|
||||
GUID: "item1",
|
||||
FeedId: feed.Id,
|
||||
Title: "Title 1",
|
||||
Date: time.Now(),
|
||||
}
|
||||
|
||||
// 1. Initial creation
|
||||
db.CreateItems([]Item{item})
|
||||
|
||||
var lastArrived1 time.Time
|
||||
err := db.db.QueryRow("select last_arrived from items where guid = ?", item.GUID).Scan(&lastArrived1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
time.Sleep(time.Second * 10)
|
||||
|
||||
// 2. Update on conflict
|
||||
db.CreateItems([]Item{item})
|
||||
|
||||
var lastArrived2 time.Time
|
||||
err = db.db.QueryRow("select last_arrived from items where guid = ?", item.GUID).Scan(&lastArrived2)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !lastArrived2.After(lastArrived1) {
|
||||
t.Errorf("expected last_arrived to be updated. old: %v, new: %v", lastArrived1, lastArrived2)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ var migrations = []func(*sql.Tx) error{
|
||||
m08_normalize_datetime,
|
||||
m09_change_item_index,
|
||||
m10_add_item_medialinks,
|
||||
m11_add_item_last_arrived,
|
||||
}
|
||||
|
||||
var maxVersion = int64(len(migrations))
|
||||
@@ -332,3 +333,9 @@ func m10_add_item_medialinks(tx *sql.Tx) error {
|
||||
_, err := tx.Exec(sql)
|
||||
return err
|
||||
}
|
||||
|
||||
func m11_add_item_last_arrived(tx *sql.Tx) error {
|
||||
sql := `alter table items add column last_arrived datetime`
|
||||
_, err := tx.Exec(sql)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user