From 9f80c2746f3bb0c502b813c8d7a71992af58e2bd Mon Sep 17 00:00:00 2001 From: otrapersona <47833943+otrapersona@users.noreply.github.com> Date: Sat, 13 Mar 2021 13:46:18 -0600 Subject: [PATCH 1/2] Add trigger MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes symptom but not cause 🤷‍♀️ --- main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.py b/main.py index e0a11b7..5e7bd29 100755 --- a/main.py +++ b/main.py @@ -87,6 +87,7 @@ db = sqlite3.connect("toots.db") db.text_factory=str c = db.cursor() c.execute("CREATE TABLE IF NOT EXISTS `toots` (sortid INTEGER UNIQUE PRIMARY KEY AUTOINCREMENT, id VARCHAR NOT NULL, cw INT NOT NULL DEFAULT 0, userid VARCHAR NOT NULL, uri VARCHAR NOT NULL, content VARCHAR NOT NULL)") +c.execute("CREATE TRIGGER IF NOT EXISTS `dedup` AFTER INSERT ON toots FOR EACH ROW BEGIN DELETE FROM toots WHERE rowid NOT IN (SELECT MIN(sortid) FROM toots GROUP BY id ); END; ") db.commit() tableinfo = c.execute("PRAGMA table_info(`toots`)").fetchall() @@ -121,6 +122,7 @@ if not found: c.execute("DROP TABLE `toots`") c.execute("ALTER TABLE `toots_temp` RENAME TO `toots`") + c.execute("CREATE TRIGGER IF NOT EXISTS `dedup` AFTER INSERT ON toots FOR EACH ROW BEGIN DELETE FROM toots WHERE rowid NOT IN (SELECT MIN(sortid) FROM toots GROUP BY id ); END; ") db.commit() From be8227c70a63d02cdc1967b93d54f15f63d9d167 Mon Sep 17 00:00:00 2001 From: otrapersona <47833943+otrapersona@users.noreply.github.com> Date: Sat, 13 Mar 2021 13:54:32 -0600 Subject: [PATCH 2/2] Changed group of trigger I think there's a tiny chance that two posts on diff instances have the same id, problem solved by using the uri. --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 5e7bd29..83ea266 100755 --- a/main.py +++ b/main.py @@ -87,7 +87,7 @@ db = sqlite3.connect("toots.db") db.text_factory=str c = db.cursor() c.execute("CREATE TABLE IF NOT EXISTS `toots` (sortid INTEGER UNIQUE PRIMARY KEY AUTOINCREMENT, id VARCHAR NOT NULL, cw INT NOT NULL DEFAULT 0, userid VARCHAR NOT NULL, uri VARCHAR NOT NULL, content VARCHAR NOT NULL)") -c.execute("CREATE TRIGGER IF NOT EXISTS `dedup` AFTER INSERT ON toots FOR EACH ROW BEGIN DELETE FROM toots WHERE rowid NOT IN (SELECT MIN(sortid) FROM toots GROUP BY id ); END; ") +c.execute("CREATE TRIGGER IF NOT EXISTS `dedup` AFTER INSERT ON toots FOR EACH ROW BEGIN DELETE FROM toots WHERE rowid NOT IN (SELECT MIN(sortid) FROM toots GROUP BY uri ); END; ") db.commit() tableinfo = c.execute("PRAGMA table_info(`toots`)").fetchall() @@ -122,7 +122,7 @@ if not found: c.execute("DROP TABLE `toots`") c.execute("ALTER TABLE `toots_temp` RENAME TO `toots`") - c.execute("CREATE TRIGGER IF NOT EXISTS `dedup` AFTER INSERT ON toots FOR EACH ROW BEGIN DELETE FROM toots WHERE rowid NOT IN (SELECT MIN(sortid) FROM toots GROUP BY id ); END; ") + c.execute("CREATE TRIGGER IF NOT EXISTS `dedup` AFTER INSERT ON toots FOR EACH ROW BEGIN DELETE FROM toots WHERE rowid NOT IN (SELECT MIN(sortid) FROM toots GROUP BY uri ); END; ") db.commit()