NYCPHP Meetup

NYPHP.org

[nycphp-talk] the stale V in MVC web apps

Daniel Convissor danielc at analysisandsolutions.com
Wed Mar 4 17:44:40 EST 2009


Hola David:

On Wed, Mar 04, 2009 at 10:49:01AM -0500, David Mintz wrote:
> I've got users working collaboratively all day long on a set of database
> records. The view in front of them is frequently stale.

There are many ways to do this, as this thread shows.  The best option 
depends on exactly what you need to do.  That said, here's an outline of 
what I'd do, in theory.

Server has two methods.  First is "get_records()" which outputs the 
record set and has an optional parameter "edited_since."  Second is 
"get_latest_time()" and it outputs the result of
"COALESCE(MAX(modification_time), MAX(creation_time)) AS latest_time."

When the front end first loads the page, it get all of the results and 
puts the latest_time aside for future reference.

The front end has a radio button with three options to the question "What 
do you want to do if these results get updated on the server?"
* automatically refresh
* ask me what to do
* ignore

If the user has chosen auto or ask, run a poller at some interval.  The 
poller can work in several ways...

a) You can call get_latest_time() and check it against the latest_time 
you set aside earlier.  If there was a change and the user wants the 
latest data, you can then either get all records or just get the records 
that have changed.

b) You can pass latest_time to get_records() and if anything comes back, 
update/add those rows in the display if the user wants to.  This option 
seems a bit sweeter since it does everything in one shot.


To the folks who suggested using an MD5 hash: sure, that will work.  But 
that has a lot of overhead, since you need to go through the entire 
result set to calculate the hash.

--Dan

-- 
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
            data intensive web and database programming
                http://www.AnalysisAndSolutions.com/
 4015 7th Ave #4, Brooklyn NY 11232  v: 718-854-0335 f: 718-854-0409



More information about the talk mailing list