Skip to content

Commit

Permalink
Homepage: Improve front page performance by avoiding extra queries
Browse files Browse the repository at this point in the history
Read blog posts from cached JSON and the latest builds directly
from BDB. Guesstimate a good number of posts to show by looking
at the content length.

Only open one database connection per request.
  • Loading branch information
skyjake committed Mar 9, 2017
1 parent 9cd004d commit 4edcef6
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 160 deletions.
10 changes: 10 additions & 0 deletions web/classes/frontcontroller.class.php
Expand Up @@ -42,6 +42,7 @@ class FrontController
private $_plugins;
private $_actions;
private $_contentCache = NULL;
private $_db = NULL;

private $_visibleErrors = false;

Expand Down Expand Up @@ -105,6 +106,10 @@ private function __construct($config)
ini_set('display_errors', (bool) $this->_visibleErrors);
ini_set('display_startup_errors', (bool) $this->_visibleErrors);
set_error_handler(array(&$this,"ErrorHandler"));

// Open a database connection.
require_once(DENG_API_DIR.'/include/database.inc.php');
$this->_db = db_open();

// Locate plugins.
$this->_plugins = new Plugins(DIR_PLUGINS);
Expand Down Expand Up @@ -140,6 +145,11 @@ public function &request()
{
return $this->_request;
}

public function &database()
{
return $this->_db;
}

public function &plugins()
{
Expand Down
3 changes: 1 addition & 2 deletions web/plugins/pages/pages.php
Expand Up @@ -122,7 +122,7 @@ function generate_download_badge($db, $file_id)
function generate_badges($platform, $type)
{
// Find the latest suitable files.
$db = db_open();
$db = FrontController::fc()->database();
$result = db_latest_files($db, $platform, $type);
$latest_build = 0;
while ($row = $result->fetch_assoc()) {
Expand All @@ -135,7 +135,6 @@ function generate_badges($platform, $type)
}
generate_download_badge($db, $row['id']);
}
$db->close();
}

class PagesPlugin extends Plugin implements Actioner, RequestInterpreter
Expand Down

0 comments on commit 4edcef6

Please sign in to comment.