http - Queueing of requiests to update data on client or server side? -


so have grid sortable columns. on each sorting, there action updatagridsorting sends server post request new data.

on server, there method updates data in database. in pretty bad way: no locks prevent simultaneous data updates in db, lock read while updating.

therefore have issue: when user clicks several times on sorting, several requests sent, overwrite data simultaneously , create dirty data.

so workaround queue requests on side , not update database before previous update finished. on side it's better create queue?

right intention is:

savegridcolumnsorting = (datatosend, action, forcesend) ->     if not forcesend         queue.enqueue(datatosend.id);     if queue.lenght > 1 , not forcesend         return     $.ajax(             url: url + "/" + action,             data: datatosend,             success: (data) ->                 if (queue.lenght > 0)                     savegridcolumnsorting(queue.dequeue());         )     return 

also, if can see xy problem, please refer pattern or trustable source fix x in answer.

especially if system intended more 1 user (like said in comments), there obvious risks in doing client-side. starters, it's security vulnerability. secondly, happens when more 1 user issuing calls?

so should happen on server. @ same time, perhaps it's not wisest choice use queue such task, since doing this, 1 user create denial-of-service others, filling queue, or causing whole thing crash lack of memory.

there's question of happens when user requests sort 1 way, , then, before database re-read, user b has submitted own sort request, processed. not first user wrong output, possibly without being aware of it?

to avoid of these issues—and provided it's possible in terms of memory, , other information possibly not provided—you might choose keep cached copy of result-set, sort per-request, instead of modifying actual database. alternatively, if database engine can sorting in read-only way, that's should used.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -