rpc: delay getting DB connection until absolutely necessary

Signed-off-by: Dan McGee <dan@archlinux.org>
Signed-off-by: Loui Chang <louipc.ist@gmail.com>
This commit is contained in:
Dan McGee 2009-02-14 17:16:39 -06:00 committed by Loui Chang
parent 6afc46cb4a
commit 0caa949e41

View file

@ -33,8 +33,6 @@ class AurJSON {
public function handle($http_data) { public function handle($http_data) {
// set content type header to json // set content type header to json
header('content-type: application/json'); header('content-type: application/json');
// set up db connection.
$this->dbh = db_connect();
// handle error states // handle error states
if ( !isset($http_data['type']) || !isset($http_data['arg']) ) { if ( !isset($http_data['type']) || !isset($http_data['arg']) ) {
@ -43,6 +41,9 @@ class AurJSON {
// do the routing // do the routing
if ( in_array($http_data['type'], $this->exposed_methods) ) { if ( in_array($http_data['type'], $this->exposed_methods) ) {
// set up db connection.
$this->dbh = db_connect();
// ugh. this works. I hate you php. // ugh. this works. I hate you php.
$json = call_user_func_array(array(&$this,$http_data['type']), $json = call_user_func_array(array(&$this,$http_data['type']),
$http_data['arg']); $http_data['arg']);
@ -103,7 +104,7 @@ class AurJSON {
$search_data = array(); $search_data = array();
while ( $row = mysql_fetch_assoc($result) ) { while ( $row = mysql_fetch_assoc($result) ) {
array_push($search_data, $row); array_push($search_data, $row);
} }
mysql_free_result($result); mysql_free_result($result);
return $this->json_results('search', $search_data); return $this->json_results('search', $search_data);