Skip to content

Commit

Permalink
Prep values upon display, not when getting data. Major speed improvme…
Browse files Browse the repository at this point in the history
…nts.
  • Loading branch information
jegelstaff committed Feb 8, 2025
1 parent 02a59f5 commit f2a034a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 49 deletions.
70 changes: 36 additions & 34 deletions modules/formulize/include/entriesdisplay.php
Original file line number Diff line number Diff line change
Expand Up @@ -1618,7 +1618,7 @@ function drawEntries($fid, $cols, $frid, $currentURL, $uid, $settings, $member_h
$useSearch = $screen->getVar('usesearch') ? $screen->getVar('usesearch') : 0;
$hiddenColumns = $screen->getVar('hiddencolumns');
$deColumns = $screen->getVar('decolumns');
$deDisplay = $screen->getVar('dedisplay');
$displayIconsToActivateElements = $screen->getVar('dedisplay');
$useSearchCalcMsgs = $screen->getVar('usesearchcalcmsgs');
foreach($screen->getVar('customactions') as $caid=>$thisCustomAction) {
if($thisCustomAction['appearinline'] == 1) {
Expand Down Expand Up @@ -1868,9 +1868,9 @@ function drawEntries($fid, $cols, $frid, $currentURL, $uid, $settings, $member_h
$col = $cols[$i];
$colhandle = $settings['columnhandles'][$i];

$templateVariables['columnHandles'][] = $colhandle;
$colElementObject = $element_handler->get($colhandle);
$templateVariables['columnFormIds'][] = $colElementObject ? $colElementObject->getVar('id_form') : $fid;
$templateVariables['columnHandles'][] = $colhandle;
$colElementObject = $element_handler->get($colhandle);
$templateVariables['columnFormIds'][] = $colElementObject ? $colElementObject->getVar('id_form') : $fid;

if($col == "creation_uid" OR $col == "mod_uid") {
$userObject = $member_handler->getUser(display($entry, $col));
Expand All @@ -1888,57 +1888,59 @@ function drawEntries($fid, $cols, $frid, $currentURL, $uid, $settings, $member_h
// set in the display function, corresponds to the entry id of the record in the form where the current value was retrieved from. If there is more than one local entry id, because of a one to many framework, then this will be an array that corresponds to the order of the values returned by display.
$currentColumnLocalId = $GLOBALS['formulize_mostRecentLocalId'];

$elementDisplayed = false;
$elementDisplayed = false;
// if we're supposed to display this column as an element... (only show it if they have permission to update this entry)
if (in_array($colhandle, $deColumns)) {
include_once XOOPS_ROOT_PATH . "/modules/formulize/include/elementdisplay.php";
if($frid) { // need to work out which form this column belongs to, and use that form's entry ID. Need to loop through the entry to find all possible internal IDs, since a subform situation would lead to multiple values appearing in a single cell, so multiple displayElement calls would be made each with their own internal ID.
foreach($entry as $entryFormHandle=>$entryFormData) {
$multiValueBRNeeded = false;
foreach($entryFormData as $internalID=>$entryElements) {
$deThisIntId = false;
foreach($entryElements as $entryHandle=>$values) {
if($entryHandle == $col AND $internalID) { // we found the element that we're trying to display
$displayElementObject = $element_handler->get($entryHandle);
if(formulizePermHandler::user_can_edit_entry($displayElementObject->getVar('id_form'), $uid, $internalID)) {
if($deThisIntId) { print "\n<br />\n"; } // could be a subform so we'd display multiple values
$deThisIntId = false;
foreach($entryElements as $entryHandle=>$values) {
$values = is_array($values) ? $values[0] : $values;
$values = prepvalues($values, $entryHandle, $internalID);
if($entryHandle == $col AND $internalID) { // we found the element that we're trying to display
$displayElementObject = $element_handler->get($entryHandle);
if(formulizePermHandler::user_can_edit_entry($displayElementObject->getVar('id_form'), $uid, $internalID)) {
if($deThisIntId) { print "\n<br />\n"; } // could be a subform so we'd display multiple values
list($allowed, $isDisabled) = elementIsAllowedForUserInEntry($displayElementObject, $internalID);
if($deDisplay AND !$isDisabled) {
if($multiValueBRNeeded) { print "\n<br />\n"; } // in the case of multiple values, split them based on this
print '<div id="deDiv_'.$colhandle.'_'.$internalID.'_'.$deInstanceCounter.'">';
print getHTMLForList($values, $colhandle, $internalID, $deDisplay, $textWidth, $internalID, $fid, $cellRowAddress, $i, $deInstanceCounter); // $internalID passed in in place of $currentColumnLocalId because we are manually looping through the data to get to the lowest level, so we can be sure of the local id that is in use, and it won't be an array, etc (unless we're showing a checkbox element??? or something else with multiple values??? - probably doesn't matter because the entry id is the same for all values of a single element that allows multiple selection)
print "</div>";
$deInstanceCounter++;
} else {
if($deThisIntId) { print "\n<br />\n"; } // extra break to separate multiple form elements in the same cell, for readability/usability
// NEEDS DEBUG - ELEMENTS NOT DISPLAYING
$colHandleElementObject = $element_handler->get($colhandle);
$colHandleElementObject = overrideSeparatorToLineBreak($colHandleElementObject);
displayElement("", $colHandleElementObject, $internalID);
}
$deThisIntId = true;
$multiValueBRNeeded = true;
$elementDisplayed = true;
}
}
}
if($displayIconsToActivateElements AND !$isDisabled) {
if($multiValueBRNeeded) { print "\n<br />\n"; } // in the case of multiple values, split them based on this
print '<div id="deDiv_'.$colhandle.'_'.$internalID.'_'.$deInstanceCounter.'">';
print getHTMLForList($values, $colhandle, $internalID, $displayIconsToActivateElements, $textWidth, $internalID, $fid, $cellRowAddress, $i, $deInstanceCounter); // $internalID passed in in place of $currentColumnLocalId because we are manually looping through the data to get to the lowest level, so we can be sure of the local id that is in use, and it won't be an array, etc (unless we're showing a checkbox element??? or something else with multiple values??? - probably doesn't matter because the entry id is the same for all values of a single element that allows multiple selection)
print "</div>";
$deInstanceCounter++;
} else {
if($deThisIntId) { print "\n<br />\n"; } // extra break to separate multiple form elements in the same cell, for readability/usability
// NEEDS DEBUG - ELEMENTS NOT DISPLAYING
$colHandleElementObject = $element_handler->get($colhandle);
$colHandleElementObject = overrideSeparatorToLineBreak($colHandleElementObject);
displayElement("", $colHandleElementObject, $internalID);
}
$deThisIntId = true;
$multiValueBRNeeded = true;
$elementDisplayed = true;
}
}
}
}
}
} elseif(formulizePermHandler::user_can_edit_entry($fid, $uid, $entry_id)) { // display based on the mainform entry id
if($deDisplay) {
if($displayIconsToActivateElements) {
print '<div id="deDiv_'.$colhandle.'_'.$entry_id.'_'.$deInstanceCounter.'">';
print getHTMLForList($value,$colhandle,$entry_id, $deDisplay, $textWidth, $currentColumnLocalId, $fid, $cellRowAddress, $i, $deInstanceCounter);
print getHTMLForList($value,$colhandle,$entry_id, $displayIconsToActivateElements, $textWidth, $currentColumnLocalId, $fid, $cellRowAddress, $i, $deInstanceCounter);
print "</div>";
$deInstanceCounter++;
} else {
// NEEDS DEBUG - ELEMENTS NOT DISPLAYING
displayElement("", $colhandle, $entry_id); // works for mainform only! To work on elements from a framework, we need to figure out the form the element is from, and the entry ID in that form, which is done above
}
$elementDisplayed = true;
$elementDisplayed = true;
}
$GLOBALS['formulize_displayElement_LOE_Used'] = true;
}
if(!$elementDisplayed AND ($col != "creation_uid" AND $col!= "mod_uid" AND $col != "entry_id")) {
if(!$elementDisplayed AND ($col != "creation_uid" AND $col!= "mod_uid" AND $col != "entry_id")) {
print getHTMLForList($value, $col, $entry_id, 0, $textWidth, $currentColumnLocalId, $fid, $cellRowAddress, $i);
} elseif(!$elementDisplayed) { // no special formatting on the uid columns:
print $value;
Expand Down
28 changes: 13 additions & 15 deletions modules/formulize/include/extract.php
Original file line number Diff line number Diff line change
Expand Up @@ -1212,12 +1212,13 @@ function processGetDataResults($resultData) {
// Check to see if this is a main entry that has already been catalogued, and if so, then skip it
if($curFormAlias == "main" AND isset($writtenMains[$entryIdIndex['main']])) {
continue;
}
formulize_benchmark("processing ".$field.": $value");
//formulize_benchmark("preping value...");
$valueArray = prepvalues($value, $elementHandle, $entryIdIndex[$curFormAlias]); // note...metadata fields must not be in an array for compatibility with the 'display' function.
//formulize_benchmark("done preping value");
$masterResults[$masterIndexer][getFormTitle($curFormId)][$entryIdIndex[$curFormAlias]][$elementHandle] = $valueArray;
}
if(isMetaDataField($elementHandle)) {
$valueArray = $value;
} else {
$valueArray = array($value);
}
$masterResults[$masterIndexer][getFormTitle($curFormId)][$entryIdIndex[$curFormAlias]][$elementHandle] = $valueArray;
} // end of foreach field loop within a record
} // end of main while loop for all records
unset($queryRes[$queryResIndex]);
Expand Down Expand Up @@ -2365,23 +2366,20 @@ function getFormHandlesFromEntry($entry) {

function display($entry, $handle, $id=null, $localid="NULL") {

if(is_numeric($id)) {
$entry = $entry[$id];
}

$entry = is_numeric($id) ? $entry[$id] : $entry;
if(!$formhandle = getFormHandleFromEntry($entry, $handle)) { return ""; } // return nothing if handle is not part of entry

$GLOBALS['formulize_mostRecentLocalId'] = array();
foreach($entry[$formhandle] as $lid=>$elements) {
if($localid == "NULL" OR $lid == $localid) {
if(is_array($elements[$handle])) {
foreach($elements[$handle] as $value) {
$foundValues[] = $value;
$GLOBALS['formulize_mostRecentLocalId'][] = $lid;
if(is_array($elements[$handle])) { // will only ever be one item in this array! holdover from when we used to prep values as part of preparing dataset, and everything, even single values, was put into an array. Now we put the raw DB value into an array, and prep it here. Sticking with it in an array is consistent for existing logic that expects only metadata values to not be in an array, which is hacky, but less disruptive.
foreach(prepvalues($elements[$handle][0], $handle, $lid) as $thisValue) {
$foundValues[] = $thisValue;
}
$GLOBALS['formulize_mostRecentLocalId'][] = $lid;
} else { // the handle is for metadata, all other fields will be arrays in the dataset
$GLOBALS['formulize_mostRecentLocalId'] = $lid;
return $elements[$handle];
return prepvalues($elements[$handle], $handle, $lid);
}
}
}
Expand Down

0 comments on commit f2a034a

Please sign in to comment.