address race condition cancelling similar messages fixes #6366
address race condition cancelling similar messages fixes #6366

use a single query to do the update to avoid causing errors,
and do it in a transaction with the creation of the new messages
so that another process has a minimal period to sneak in between
the update old and the create new

Change-Id: I80595a1e168221e39bf88c164ed110b3b11fa630
Reviewed-on: https://gerrit.instructure.com/8396
Tested-by: Hudson <dfb64870173313a9a7b56f814c8e3b33e268497a@instructure.com>
Reviewed-by: Jon Jensen <44f878afe53efc66b76772bd845eb65944ed8232@instructure.com>

narigone/canvas,gbleydon/canvas-lms,fronteerio/canvas-lms,nditech/red-innovadores-lms,eCNAP/CANVAS,wimemx/Canvas,ankithbti/canvas_lms,dgynn/canvas-lms,venturehive/canvas-lms,arrivu/arrivu-lms,nditech/red-innovadores-lms,grahamb/canvas-lms,greyhwndz/canvas-lms,efrj/canvas-lms,whalejasmine/canvas-lms,snehakachroo1/LSI_replica,snehakachroo1/LSI_replica,redconfetti/canvas-lms,snehakachroo1/LSI_replica,arrivu/hoodemo,AndranikMarkosyan/lms,wye0220/shindig-canvas,roxolan/canvas-lms,SwinburneOnline/canvas-lms,sfu/canvas-lms,arrivu/jigsaw-lms,Rvor/canvas-lms,ottenhoff/canvas-lms,redconfetti/canvas-lms,sfu/canvas-lms,merichar/canvas-lms,roxolan/canvas-lms,va7map/canvas-lms,arrivu/qibla-ecampus,sfu/canvas-lms,fronteerio/canvas-lms,icelab/canvas,ottenhoff/canvas-lms,arrivu/jigsaw-lms,greyhwndz/canvas-lms,arrivu/qibla-ecampus,kyroskoh/canvas-lms,jay3126/canvas-lms,em2/canvas-lms,ankithbti/canvas_lms,venturehive/canvas-lms,loganrun/pincan,landonwilkins/canvas-lms,narigone/canvas,sfu/canvas-lms,matematikk-mooc/canvas-lms,samuels410/greatlakes-lms,narigone/canvas,parbros/red-innovadores-lms,skmezanul/canvas-lms,samuels410/greatlakes-lms,shidao-fm/canvas-lms,Unow/canvas-lms,Unow/ins,whalejasmine/canvas-lms,Unow/canvas-lms,efrj/canvas-lms,merichar/canvas-lms,landonwilkins/canvas-lms,eCNAP/CANVAS,kyroskoh/canvas-lms,nditech/red-innovadores-lms,venturehive/canvas-lms,djbender/canvas-lms,redconfetti/canvas-lms,djbender/canvas-lms,eCNAP/CANVAS,arrivu/qibla-ecampus,arrivu/hiring-site,Jyaasa/canvas-lms,instructure/canvas-lms,usmschuck/canvas,efrj/canvas-lms,skmezanul/canvas-lms,shidao-fm/canvas-lms,gbleydon/canvas-lms,antoniuslin/canvas-lms,matematikk-mooc/canvas-lms,usmschuck/canvas,instructure/canvas-lms,djbender/canvas-lms,em2/canvas-lms,AndranikMarkosyan/lms,leftplusrightllc/canvas-lms,instructure/canvas-lms,whalejasmine/canvas-lms,landonwilkins/canvas-lms,arrivu/hoodemo,arrivu/arrivu-lms,rup/Tarrax,instructure/canvas-lms,HotChalk/canvas-lms,sdeleon28/canvas-lms,samuels410/greatlakes-lms,sdeleon28/canvas-lms,SwinburneOnline/canvas-lms,SwinburneOnline/canvas-lms,ShreniiNepal/shrenii_lmp,loganrun/pincan,skmezanul/canvas-lms,grahamb/canvas-lms,icelab/canvas,parbros/red-innovadores-lms,Unow/ins,juoni/canvas-lms,wimemx/Canvas,fronteerio/canvas-lms,instructure/canvas-lms,icelab/canvas,AndranikMarkosyan/lms,Unow/ins,arrivu/hiring-site,utkarshx/canvas-lms,matematikk-mooc/canvas-lms,nditech/red-innovadores-lms,em2/canvas-lms,wrdsb/canvas-lms,sdeleon28/canvas-lms,redconfetti/canvas-lms,arrivu/hoodemo,leftplusrightllc/canvas-lms,ankithbti/canvas_lms,sli7246/canvas_branch,shidao-fm/canvas-lms,ottenhoff/canvas-lms,HotChalk/canvas-lms,instructure/canvas-lms,utkarshx/canvas-lms,Jyaasa/canvas-lms,wrdsb/canvas-lms,sfu/canvas-lms,AndranikMarkosyan/lms,roxolan/canvas-lms,snehakachroo1/LSI_replica,landonwilkins/canvas-lms,utkarshx/canvas-lms,grahamb/canvas-lms,sdeleon28/canvas-lms,sli7246/canvas_branch,Unow/canvas-lms,fronteerio/canvas-lms,jay3126/canvas-lms,dgynn/canvas-lms,tgroshon/canvas-lms,parbros/red-innovadores-lms,kyroskoh/canvas-lms,HotChalk/canvas-lms,antoniuslin/canvas-lms,Rvor/canvas-lms,usmschuck/canvas,kyroskoh/canvas-lms,dgynn/canvas-lms,efrj/canvas-lms,gbleydon/canvas-lms,sli7246/canvas_branch,leftplusrightllc/canvas-lms,Jyaasa/canvas-lms,matematikk-mooc/canvas-lms,samuels410/greatlakes-lms,wye0220/shindig-canvas,grahamb/canvas-lms,va7map/canvas-lms,sfu/canvas-lms,ShreniiNepal/shrenii_lmp,leftplusrightllc/canvas-lms,va7map/canvas-lms,merichar/canvas-lms,ShreniiNepal/shrenii_lmp,arrivu/hiring-site,greyhwndz/canvas-lms,tgroshon/canvas-lms,Jyaasa/canvas-lms,Rvor/canvas-lms,juoni/canvas-lms,wimemx/Canvas,greyhwndz/canvas-lms,juoni/canvas-lms,djbender/canvas-lms,arrivu/jigsaw-lms,jay3126/canvas-lms,va7map/canvas-lms,antoniuslin/canvas-lms,SwinburneOnline/canvas-lms,shidao-fm/canvas-lms,sfu/canvas-lms,instructure/canvas-lms,HotChalk/canvas-lms,ShreniiNepal/shrenii_lmp,eCNAP/CANVAS,loganrun/pincan,juoni/canvas-lms,wrdsb/canvas-lms,venturehive/canvas-lms,dgynn/canvas-lms,wye0220/shindig-canvas,rup/Tarrax,tgroshon/canvas-lms,Rvor/canvas-lms,grahamb/canvas-lms,tgroshon/canvas-lms,rup/Tarrax,narigone/canvas,antoniuslin/canvas-lms,usmschuck/canvas,whalejasmine/canvas-lms,arrivu/arrivu-lms,utkarshx/canvas-lms,jay3126/canvas-lms,roxolan/canvas-lms,wrdsb/canvas-lms,skmezanul/canvas-lms