listview and amount of delegate function calls
3 posts
• Page 1 of 1
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.
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
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
3 posts
• Page 1 of 1
Who is onlineUsers browsing this forum: No registered users and 33 guests |