This commit is contained in:
Nazar Kanaev
2024-09-25 11:01:03 +01:00
parent f71792d6a5
commit 2a4d974965
6 changed files with 33 additions and 34 deletions

View File

@@ -79,22 +79,21 @@ type MarkFilter struct {
type ItemList []Item
func (list ItemList) Len() int {
return len(list)
return len(list)
}
func (list ItemList) SortKey(i int) string {
return list[i].Date.Format(time.RFC3339) + "::" + list[i].GUID
return list[i].Date.Format(time.RFC3339) + "::" + list[i].GUID
}
func (list ItemList) Less(i, j int) bool {
return list.SortKey(i) < list.SortKey(j)
return list.SortKey(i) < list.SortKey(j)
}
func (list ItemList) Swap(i, j int) {
list[i], list[j] = list[j], list[i]
list[i], list[j] = list[j], list[i]
}
func (s *Storage) CreateItems(items []Item) bool {
tx, err := s.db.Begin()
if err != nil {
@@ -104,8 +103,8 @@ func (s *Storage) CreateItems(items []Item) bool {
now := time.Now().UTC()
itemsSorted := ItemList(items)
sort.Sort(itemsSorted)
itemsSorted := ItemList(items)
sort.Sort(itemsSorted)
for _, item := range itemsSorted {
_, err = tx.Exec(`

View File

@@ -16,16 +16,16 @@ var migrations = []func(*sql.Tx) error{
m06_fill_missing_dates,
m07_add_feed_size,
m08_normalize_datetime,
m09_change_item_index,
m09_change_item_index,
}
var maxVersion = int64(len(migrations))
func migrate(db *sql.DB) error {
var version int64
if err := db.QueryRow("pragma user_version").Scan(&version); err != nil {
return err
}
if err := db.QueryRow("pragma user_version").Scan(&version); err != nil {
return err
}
if version >= maxVersion {
return nil

View File

@@ -14,10 +14,10 @@ type Storage struct {
func New(path string) (*Storage, error) {
if pos := strings.IndexRune(path, '?'); pos == -1 {
params := "_journal=WAL&_sync=NORMAL&_busy_timeout=5000&cache=shared"
log.Printf("opening db with params: %s", params)
path = path + "?" + params
}
params := "_journal=WAL&_sync=NORMAL&_busy_timeout=5000&cache=shared"
log.Printf("opening db with params: %s", params)
path = path + "?" + params
}
db, err := sql.Open("sqlite3", path)
if err != nil {