aboutsummaryrefslogtreecommitdiff
path: root/db.go
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-02-29 10:01:42 +0100
committerAlex Auvolat <alex@adnab.me>2020-02-29 10:01:42 +0100
commit38a3f1bdb18159cc4808fa86280da55f0599dcc8 (patch)
tree9976cd829d5fc3953d382dcc955a7b270f2ab728 /db.go
parent1c038995be9f869be1b69a604e42096807806676 (diff)
downloadeasybridge-38a3f1bdb18159cc4808fa86280da55f0599dcc8.tar.gz
easybridge-38a3f1bdb18159cc4808fa86280da55f0599dcc8.zip
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.
Diffstat (limited to 'db.go')
-rw-r--r--db.go12
1 files changed, 9 insertions, 3 deletions
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
}