Index: branches/5.2.x/core/units/helpers/page_helper.php =================================================================== --- branches/5.2.x/core/units/helpers/page_helper.php +++ branches/5.2.x/core/units/helpers/page_helper.php @@ -17,6 +17,13 @@ class PageHelper extends kHelper { /** + * Content block cache per page. + * + * @var array + */ + protected $contentBlockCache = array(); + + /** * Returns page info * * @param int $page_id @@ -421,16 +428,39 @@ { $page_id = $page->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'; - } - else { - $revision_clause = $this->getRevsionWhereClause($page_id, $page->GetDBField('LiveRevisionNumber'), 'pr.'); + 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(); } + // 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);