From de398786bea61584d64f60d5faad123e5ca55c05 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Sat, 15 Oct 2022 19:28:57 +0000 Subject: [PATCH] So far I've gotten the triggers all wrong. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4009 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- src/ssb.db.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/ssb.db.c b/src/ssb.db.c index c4af262b..e2864ada 100644 --- a/src/ssb.db.c +++ b/src/ssb.db.c @@ -142,12 +142,6 @@ void tf_ssb_db_init(tf_ssb_t* ssb) " ref TEXT, " " UNIQUE(message, ref)" ")"); - _tf_ssb_db_exec(db, "CREATE TRIGGER IF NOT EXISTS messages_ai_refs AFTER INSERT ON messages BEGIN " - "INSERT INTO messages_refs(message, ref) " - "SELECT new.id, j.value FROM json_each(new.content) as j WHERE " - "j.value LIKE '&%.sha256' OR " - "j.value LIKE '%%%.sha256' OR " - "j.value LIKE '@%.ed25519'; END"); printf("Populating messages_refs...\n"); _tf_ssb_db_exec(db, "INSERT INTO messages_refs(message, ref) " "SELECT messages.id, j.value FROM messages, json_each(messages.content) as j WHERE " @@ -158,6 +152,14 @@ void tf_ssb_db_init(tf_ssb_t* ssb) printf("Done.\n"); } + _tf_ssb_db_exec(db, "DROP TRIGGER IF EXISTS messages_ai_refs"); + _tf_ssb_db_exec(db, "CREATE TRIGGER IF NOT EXISTS messages_ai_refs AFTER INSERT ON messages BEGIN " + "INSERT INTO messages_refs(message, ref) " + "SELECT DISTINCT new.id, j.value FROM json_each(new.content) as j WHERE " + "j.value LIKE '&%.sha256' OR " + "j.value LIKE '%%%.sha256' OR " + "j.value LIKE '@%.ed25519' " + "ON CONFLICT DO NOTHING; END"); _tf_ssb_db_exec(db, "DROP TRIGGER IF EXISTS messages_ad_refs"); _tf_ssb_db_exec(db, "CREATE TRIGGER IF NOT EXISTS messages_ad_refs AFTER DELETE ON messages BEGIN DELETE FROM messages_refs WHERE messages_refs.message = old.id; END");