mod_storage_sql2: Only attempt to delete conflicting items if an ID/key is given
authorKim Alvefur <zash@zash.se>
Tue, 21 Jan 2014 00:51:13 +0000 (01:51 +0100)
committerKim Alvefur <zash@zash.se>
Tue, 21 Jan 2014 00:51:13 +0000 (01:51 +0100)
plugins/mod_storage_sql2.lua

index e02ad68148e22a1ea626b664337312e7f29480f2..90e9ead0c1b2308058961b52832788bc4ca405d2 100644 (file)
@@ -222,9 +222,12 @@ function archive_store:append(username, key, when, with, value)
        end
        local user,store = username,self.store;
        return engine:transaction(function()
-               local key = key or uuid.generate();
+               if key then
+                       engine:delete("DELETE FROM `prosodyarchive` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", host, user or "", store, key);
+               else
+                       key = uuid.generate();
+               end
                local t, value = serialize(value);
-               engine:delete("DELETE FROM `prosodyarchive` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", host, user or "", store, key);
                engine:insert("INSERT INTO `prosodyarchive` (`host`, `user`, `store`, `when`, `with`, `key`, `type`, `value`) VALUES (?,?,?,?,?,?,?,?)", host, user or "", store, when, with, key, t, value);
                return key;
        end);