[#6956] fix possible `message` and `user-status` duplicates

There is a tiny chance that without this fix some users which had message
duplicates because of issues with `message-id` calculation **BEFORE** `0.9.31`
still have duplicates in their DB and migrations will not pass without
this change. It only checks if the message with a new `message-id` has been
added and removes duplicate. The same way it removes duplicates from
`user-status` entity.
This commit is contained in:
Roman Volosovskyi 2018-12-05 21:00:22 +02:00
parent a91a799eb5
commit c15a57571d
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
1 changed files with 17 additions and 6 deletions

View File

@ -266,9 +266,15 @@
message-id (transport.utils/message-id from raw-payload)
raw-payload-hash (transport.utils/sha3 raw-payload)]
(vswap! old-ids->new-ids assoc prev-message-id message-id)
(aset message "message-id" message-id)
(aset message "raw-payload-hash" raw-payload-hash)
(aset message "old-message-id" old-message-id)))
(if (.objectForPrimaryKey
new-realm
"message"
message-id)
(.delete new-realm message)
(do
(aset message "message-id" message-id)
(aset message "raw-payload-hash" raw-payload-hash)
(aset message "old-message-id" old-message-id)))))
(dotimes [i (.-length user-statuses)]
(let [user-status (aget user-statuses i)
@ -276,6 +282,11 @@
new-message-id (get @old-ids->new-ids message-id)
public-key (aget user-status "public-key")
new-status-id (str new-message-id "-" public-key)]
(when (contains? @old-ids->new-ids message-id)
(aset user-status "status-id" new-status-id)
(aset user-status "message-id" new-message-id))))))
(if (.objectForPrimaryKey
new-realm
"user-status"
new-status-id)
(.delete new-realm user-status)
(when (contains? @old-ids->new-ids message-id)
(aset user-status "status-id" new-status-id)
(aset user-status "message-id" new-message-id)))))))