From 38a3f1bdb18159cc4808fa86280da55f0599dcc8 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Sat, 29 Feb 2020 10:01:42 +0100 Subject: Fix Mattermost event deduplication Mattermost assigns its own IDs to messages, thus when sending a message to Mattermost the event_seen key that has to be written must take into account that ID and not the one that we put in the event (which was the Matrix event ID) Note that for XMPP anything can be used as an ID, so using the Matrix event ID there worked, but it's actually not so good. --- db.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'db.go') diff --git a/db.go b/db.go index f9bed06..cdbdca1 100644 --- a/db.go +++ b/db.go @@ -163,6 +163,14 @@ func dbKvPut(key string, value string) { dbLockSlot(slot_key) defer dbUnlockSlot(slot_key) + dbKvPutLocked(key, value) +} + +// Variant of dbKvPut that does not take a lock, +// use this if the slot is already locked +func dbKvPutLocked(key string, value string) { + slot_key := dbKvSlotKey(key) + var entry DbKv db.Where(&DbKv{Key: key}).Assign(&DbKv{Value: value}).FirstOrCreate(&entry) dbCache.Add(slot_key, value) @@ -179,9 +187,7 @@ func dbKvTestAndSet(key string, value string) bool { return false } - var entry DbKv - db.Where(&DbKv{Key: key}).Assign(&DbKv{Value: value}).FirstOrCreate(&entry) - dbCache.Add(slot_key, value) + dbKvPutLocked(key, value) return true } -- cgit v1.2.3