listview and amount of delegate function calls

A place for users and developers of the Xataface to discuss and receive support.

Postby Scott » Fri Apr 13, 2007 8:46 pm

hi Steve,

i'm puzzled about something...

i created the situation as described here:
http://framework.weblite.ca/documentation/tutorial/getting_started/valuelists
under Example 3: Dynamic Valuelists based on the results of SQL queries

in the example the course table still has just a programid field (the linktable programcourses does not exist yet)

in the course fields.ini i put :

[ProgramID]
widget:type = select
vocabulary = programs

then, for debugging purposes, instead of putting the vocabulary query in the valuelists.ini , i put it in the course delegate (that would yield exacly the same result right?)

this is the vocabulary function:

function valuelist__programs() {
$app =& Dataface_Application::getInstance();
$record =& $app->getRecord();
$out = array();
if ($record and $record->_table->tablename == 'course' ) {
$qstring = "select ProgramID, ProgramName from Program order by ProgramName";
$res = mysql_query($qstring, df_db());
while ($row = mysql_fetch_assoc($res) ) $out[$row['ProgramID']] = $row['ProgramName'];
}
return $out;
}

then i went into the debugger and set a breakpoint in this function.
then i went to the listview of the table course

what i noticed was that the valuelist__programs functions got called for every time a record was shown in the list on one page (so for instance if i set the amount of course records to be viewed in the list to 3 , the function would get called 3 times).

this looks to be very inefficient to me. the grid is not editable so the selectboxes for the programid will not get shown anyway.
maybe this behaviour is setup for a future editable grid? if not, then the querying should behave differently for the listview (just get one programrecord for every id to be shown).

but ok, there is one thing which really puzzles me:

when i checked the record values in the debugger, the courseid never changed for every call. i would at least expect that the
$record->val('CourseID') would contain a different value for every time the delegate got called.
but it just contained the id of the first course every time the delegate function got called.

how about that?

Scott.
Scott
 
Posts: 30
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Sat Apr 14, 2007 4:43 pm

hi Scott,

It does look like this needs to be refined.. It should only be called once per request since it doesn't take a record as a parameter anyways.Ê I'll put that on my todo list.

In the mean time you can eliminate this inefficiency in your valuelist method by way of caching.

e.g.

tables_mytable {

ÊÊÊ var $cache = array();

ÊÊ ...

ÊÊ function valuelist__foo(){

ÊÊÊÊÊÊ if ( !isset($this->cache[__FUNCTION__]) ){


ÊÊÊÊÊÊÊÊÊÊÊ ... do your work to generate the valuelist

ÊÊÊÊÊÊÊÊÊÊÊ $this->cache[__FUNCTION__] = $values; // $values is your valuelist array... we are saving it in the cache.

ÊÊÊÊÊÊÊ }

ÊÊÊÊÊÊÊ return $this->cache[__FUNCTION__];


ÊÊ }



Thanks for the bug report.Ê Best regards


Steve

--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby Scott » Sat Apr 14, 2007 7:36 pm

thanks for the fast reply.
yes i tried reusing the result array too in a similar way.
i just used a static cache variable inside the function because i did not know how long my table delegate object would be "alive"....worked great too.
anyway....just testing :)
Scott
 
Posts: 30
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 26 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved