Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F1026011
D347.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Jun 13, 6:01 PM
Size
2 KB
Mime Type
text/x-diff
Expires
Sat, Jun 14, 6:01 PM (4 h, 31 m)
Engine
blob
Format
Raw Data
Handle
661662
Attached To
D347: INP-1749 - Load all content blocks of a page with a single database query
D347.diff
View Options
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);
Event Timeline
Log In to Comment