diff --git a/core/source.go b/core/source.go index 3e7c87b..7fb4cb1 100644 --- a/core/source.go +++ b/core/source.go @@ -185,6 +185,7 @@ func GetItem(db *DB, source string, id string) (Item, error) { from items where source = ? and id = ? + order by case when time = 0 then created else time end, id `, source, id) if err != nil { return Item{}, err @@ -201,6 +202,7 @@ func GetAllActiveItems(db *DB) ([]Item, error) { source, id, created, active, title, author, body, link, time, json(action) from items where active <> 0 + order by case when time = 0 then created else time end, id `) } @@ -209,6 +211,7 @@ func GetAllItems(db *DB) ([]Item, error) { select source, id, created, active, title, author, body, link, time, json(action) from items + order by case when time = 0 then created else time end, id `) } @@ -220,6 +223,7 @@ func GetActiveItemsForSource(db *DB, source string) ([]Item, error) { where source = ? and active <> 0 + order by case when time = 0 then created else time end, id `, source) } @@ -230,6 +234,7 @@ func GetAllItemsForSource(db *DB, source string) ([]Item, error) { from items where source = ? + order by case when time = 0 then created else time end, id `, source) } diff --git a/core/source_test.go b/core/source_test.go index e5af85e..fa49a51 100644 --- a/core/source_test.go +++ b/core/source_test.go @@ -73,8 +73,9 @@ func TestAddItem(t *testing.T) { if len(items) != 2 { t.Fatal("should get two items") } - AssertItemIs(t, items[0], "test/one/true/////0") - AssertItemIs(t, items[1], "test/two/true/title/author/body/link/123456") + // order is by (time ?? created) so this ordering is correct as long as you don't run it in early 1970 + AssertItemIs(t, items[0], "test/two/true/title/author/body/link/123456") + AssertItemIs(t, items[1], "test/one/true/////0") if _, err = DeactivateItem(db, "test", "one"); err != nil { t.Fatal(err)