mirror of
https://github.com/nkanaev/yarr.git
synced 2026-06-27 18:45:17 +00:00
storage: alter item trigger to perform only after relevant fields are
changed in sqlite
This commit is contained in:
@@ -22,6 +22,7 @@ var migrations = []func(*sql.Tx) error{
|
|||||||
m12_remove_feed_sizes,
|
m12_remove_feed_sizes,
|
||||||
m13_consolidate_feed_states,
|
m13_consolidate_feed_states,
|
||||||
m14_upgrade_fts5,
|
m14_upgrade_fts5,
|
||||||
|
m15_update_item_update_trigger,
|
||||||
}
|
}
|
||||||
|
|
||||||
var maxVersion = int64(len(migrations))
|
var maxVersion = int64(len(migrations))
|
||||||
@@ -420,3 +421,14 @@ func m14_upgrade_fts5(tx *sql.Tx) error {
|
|||||||
_, err := tx.Exec(sql)
|
_, err := tx.Exec(sql)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func m15_update_item_update_trigger(tx *sql.Tx) error {
|
||||||
|
_, err := tx.Exec(`
|
||||||
|
drop trigger if exists items_au;
|
||||||
|
create trigger items_au after update of title, content on items begin
|
||||||
|
insert into search(search, rowid, title, content) values('delete', old.id, old.title, strip_html(old.content));
|
||||||
|
insert into search(rowid, title, content) values (new.id, new.title, strip_html(new.content));
|
||||||
|
end;
|
||||||
|
`)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|||||||
@@ -223,16 +223,6 @@ func TestListItems(t *testing.T) {
|
|||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
|
|
||||||
// filter by search
|
|
||||||
search1 := "title111"
|
|
||||||
have = getItemGuids(db.ListItems(model.ItemFilter{Search: &search1}, 4, true, false))
|
|
||||||
want = []string{"item111"}
|
|
||||||
if !reflect.DeepEqual(have, want) {
|
|
||||||
t.Logf("want: %#v", want)
|
|
||||||
t.Logf("have: %#v", have)
|
|
||||||
t.Fail()
|
|
||||||
}
|
|
||||||
|
|
||||||
// sort by date
|
// sort by date
|
||||||
have = getItemGuids(db.ListItems(model.ItemFilter{}, 4, true, false))
|
have = getItemGuids(db.ListItems(model.ItemFilter{}, 4, true, false))
|
||||||
want = []string{"item013", "item012", "item011", "item212"}
|
want = []string{"item013", "item012", "item011", "item212"}
|
||||||
|
|||||||
Reference in New Issue
Block a user