Index: branches/5.2.x/core/units/helpers/page_helper.php =================================================================== diff -u -N -r16634 -r16667 --- branches/5.2.x/core/units/helpers/page_helper.php (.../page_helper.php) (revision 16634) +++ branches/5.2.x/core/units/helpers/page_helper.php (.../page_helper.php) (revision 16667) @@ -1,6 +1,6 @@ GetID(); + // Load all content blocks at once during regular page visits. if ( !EDITING_MODE && !$this->Application->GetVar('preview') ) { - $revision_clause = 'pr.RevisionNumber = ' . $page->GetDBField('LiveRevisionNumber') . ' AND pr.IsDraft = 0'; + if ( !isset($this->contentBlockCache[$page_id]) ) { + $where_clause = array( + $content_block->TableName . '.PageId = ' . $page_id, + 'pr.RevisionNumber = ' . $page->GetDBField('LiveRevisionNumber'), + 'pr.IsDraft = 0', + ); + + $sql = $content_block->GetSelectSQL() . ' + WHERE (' . implode(') AND (', $where_clause) . ')'; + $this->contentBlockCache[$page_id] = $this->Conn->Query($sql, 'ContentNum'); + } + + if ( isset($this->contentBlockCache[$page_id][$num]) ) { + $content_block->LoadFromHash($this->contentBlockCache[$page_id][$num]); + } + else { + $content_block->Clear(); + } + + return $content_block->isLoaded(); } - else { - $revision_clause = $this->getRevsionWhereClause($page_id, $page->GetDBField('LiveRevisionNumber'), 'pr.'); - } + // Load each content block individually with fallback to draft version, when editing content. + $where_clause = array( + $content_block->TableName . '.PageId = ' . $page_id, + $content_block->TableName . '.ContentNum = ' . $num, + $this->getRevsionWhereClause($page_id, $page->GetDBField('LiveRevisionNumber'), 'pr.'), + ); - $sql = $content_block->GetSelectSQL() . ' - WHERE (' . $content_block->TableName . '.PageId = ' . $page_id . ') AND (' . $content_block->TableName . '.ContentNum = ' . $num . ') AND (' . $revision_clause . ') + $sql = $content_block->GetSelectSQL() . ' + WHERE (' . implode(') AND (', $where_clause) . ') ORDER BY pr.IsDraft DESC, pr.RevisionNumber DESC'; $content_data = $this->Conn->GetRow($sql);