~emersion/soju-dev

Use NULL-tolerant comparison for DeliveryReceipts v1 APPLIED

Hubert Hirtz: 1
 Use NULL-tolerant comparison for DeliveryReceipts

 1 files changed, 1 insertions(+), 1 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/25166/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] Use NULL-tolerant comparison for DeliveryReceipts Export this patch

Since NULL = NULL is always FALSE, this query needs to use IS instead.
This should fix the flood of DeliveryReceipts in the DB.

See https://www.sqlite.org/lang_expr.html

> The IS and IS NOT operators work like = and != except when one or both
> of the operands are NULL. In this case, if both operands are NULL,
> then the IS operator evaluates to 1 (true) and the IS NOT operator
> evaluates to 0 (false). If one operand is NULL and the other is not,
> then the IS operator evaluates to 0 (false) and the IS NOT operator is
> 1 (true). It is not possible for an IS or IS NOT expression to
> evaluate to NULL.
---

The PostgreSQL patch also has this issue and will need a v2.

This *might* be a related to #115 since delivery receipts are loaded in
user.run(), though this was not really noticeable on my end.

https://todo.sr.ht/~emersion/soju/115

 db_sqlite.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/db_sqlite.go b/db_sqlite.go
index 6413acc..393f9d6 100644
--- a/db_sqlite.go
+++ b/db_sqlite.go
@@ -542,7 +542,7 @@ func (db *SqliteDB) StoreClientDeliveryReceipts(networkID int64, client string,
	}
	defer tx.Rollback()

	_, err = tx.Exec("DELETE FROM DeliveryReceipt WHERE network = ? AND client = ?",
	_, err = tx.Exec("DELETE FROM DeliveryReceipt WHERE network = ? AND client IS ?",
		networkID, toNullString(client))
	if err != nil {
		return err
-- 
2.33.0
Good catch, thanks! Pushed.
> This *might* be a related to #115
Unlikely, I think #115 was already happening on 0.1.0.