...

View Full Version : Update Now Or Later? (Design Question)



Tanner8
11-16-2011, 03:52 AM
Hello, I have a question on design. I am working with an AJAX query that performs a simple, straight forward table update on clicking a button. The value toggles based on the click (If it is 1 it will change it to 0 and vice verse). The thing is that you can spam click this button and make it do a bunch of useless updates, when only the last value really matters.

I was wondering if it would be a good idea to somehow store what you click somewhere, then update the table maybe every minute with just the latest choice per user. Is the effort in this even worth it or will MySQL keep up without problems? Thanks

BubikolRamios
11-16-2011, 12:24 PM
Only registered members should click, and since you are doing ajax you can emideately signal back with some graphical representation that value has changed.

Tanner8
11-16-2011, 05:26 PM
Only registered members should click, and since you are doing ajax you can emideately signal back with some graphical representation that value has changed.


Yes that's what I am doing. It's just that the user can spam click the button. I was thinking of putting a timer so you may only click it once every 2 seconds or so, but that would make it feel sluggish if you accidentally miss toggled it and want to click fast to get it back.

Old Pedant
11-16-2011, 07:50 PM
I don't see anything wrong with "buffering" the clicks in the JS code.

You'd use a setTimeout that will trigger the AJAX hit after, say, 15 seconds? If the user toggles again within that time, you clear the first timeout and set another one. Etc.

If the user leaves the page before the timeout expires, you clear the timeout and do the AJAX as part of the <body onunload="..."> processing.

Pretty simple coding, really.

Tanner8
11-16-2011, 08:05 PM
I don't see anything wrong with "buffering" the clicks in the JS code.

You'd use a setTimeout that will trigger the AJAX hit after, say, 15 seconds? If the user toggles again within that time, you clear the first timeout and set another one. Etc.

If the user leaves the page before the timeout expires, you clear the timeout and do the AJAX as part of the <body onunload="..."> processing.

Pretty simple coding, really.

Sounds good to me, I agree it's straight forward, I just wasn't sure if I should even bother with it or not. Thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum