~emersion/soju-dev

Fix DeliveryReceipt not being cleaned up v1 APPLIED

Hubert Hirtz: 1
 Fix DeliveryReceipt not being cleaned up

 1 files changed, 16 insertions(+), 0 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~emersion/soju-dev/patches/25147/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] Fix DeliveryReceipt not being cleaned up Export this patch

---
 db_sqlite.go | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/db_sqlite.go b/db_sqlite.go
index 6413acc..7c0840a 100644
--- a/db_sqlite.go
+++ b/db_sqlite.go
@@ -289,6 +289,17 @@ func (db *SqliteDB) DeleteUser(id int64) error {
	}
	defer tx.Rollback()

	_, err = tx.Exec(`DELETE FROM DeliveryReceipt
		WHERE id IN (
			SELECT DeliveryReceipt.id
			FROM DeliveryReceipt
			JOIN Network ON DeliveryReceipt.network = Network.id
			WHERE Network.user = ?
		)`, id)
	if err != nil {
		return err
	}

	_, err = tx.Exec(`DELETE FROM Channel
		WHERE id IN (
			SELECT Channel.id
@@ -422,6 +433,11 @@ func (db *SqliteDB) DeleteNetwork(id int64) error {
	}
	defer tx.Rollback()

	_, err = tx.Exec("DELETE FROM DeliveryReceipt WHERE network = ?", id)
	if err != nil {
		return err
	}

	_, err = tx.Exec("DELETE FROM Channel WHERE network = ?", id)
	if err != nil {
		return err
-- 
2.33.0
Pushed, thanks for the fix!
BTW, I wonder if we should be using cascade delete so that we can avoid these
extra queries and ensure database consistency. OTOH, updating tables is a pain
with SQLite…