return $return;
}
+ public function log_index($query) {
+ $a = get_app();
+
+ if (($a->config["system"]["db_log_index"] == "") OR ($a->config["system"]["db_log_index_watch"] == "") OR
+ (intval($a->config["system"]["db_loglimit_index"]) == 0)) {
+ return;
+ }
+
+ if (strtolower(substr($query, 0, 7)) == "explain") {
+ return;
+ }
+
+ $r = $this->q("EXPLAIN ".$query);
+ if (!dbm::is_result($r)) {
+ return;
+ }
+
+ $watchlist = explode(',', $a->config["system"]["db_log_index_watch"]);
+
+ foreach ($r AS $row) {
+ if (in_array($row['key'], $watchlist) AND
+ ($row['rows'] >= intval($a->config["system"]["db_loglimit_index"]))) {
+ $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
+ @file_put_contents($a->config["system"]["db_log_index"], datetime_convert()."\t".
+ $row['key']."\t".$row['rows']."\t".
+ basename($backtrace[1]["file"])."\t".
+ $backtrace[1]["line"]."\t".$backtrace[2]["function"]."\t".
+ substr($query, 0, 2000)."\n", FILE_APPEND);
+ }
+ }
+ }
+
public function q($sql, $onlyquery = false) {
$a = get_app();
//logger("dba: q: $stmt", LOGGER_ALL);
if ($stmt === false)
logger('dba: vsprintf error: ' . print_r(debug_backtrace(),true), LOGGER_DEBUG);
+
+ $db->log_index($stmt);
+
return $db->q($stmt);
}
$stmt = @vsprintf($sql,$args); // Disabled warnings
if ($stmt === false)
logger('dba: vsprintf error: ' . print_r(debug_backtrace(),true), LOGGER_DEBUG);
+
+ $db->log_index($stmt);
+
$db->q("SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;");
$retval = $db->q($stmt);
$db->q("SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;");
"indexes" => array(
"PRIMARY" => array("id"),
"uid_name" => array("uid", "name"),
- "uid_self" => array("uid", "self"),
+ "self_uid" => array("self", "uid"),
"alias_uid" => array("alias(32)", "uid"),
- "uid_pending" => array("uid", "pending"),
- "uid_blocked" => array("uid", "blocked"),
+ "pending_uid" => array("pending", "uid"),
+ "blocked_uid" => array("blocked", "uid"),
"uid_rel_network_poll" => array("uid", "rel", "network", "poll(64)", "archive"),
"uid_network_batch" => array("uid", "network", "batch(64)"),
"addr_uid" => array("addr(32)", "uid"),
"uid_contactid" => array("uid", "contact-id"),
"uid_profile" => array("uid", "profile"),
"uid_album_created" => array("uid", "album(32)", "created"),
+ "uid_album_scale_created" => array("uid", "album(32)", "scale", "created"),
"uid_album_resource-id_created" => array("uid", "album(32)", "resource-id(64)", "created"),
"resource-id" => array("resource-id(64)"),
)
/// @todo This query needs to be renewed. It is really slow
// At this time we just store the data in the cache
$albums = qu("SELECT COUNT(DISTINCT `resource-id`) AS `total`, `album`
- FROM `photo` USE INDEX (`uid_album_created`)
+ FROM `photo`
WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' $sql_extra
GROUP BY `album` ORDER BY `created` DESC",
intval($uid),
dbesc(t('Contact Photos'))
);
} else {
+// USE INDEX (`uid_album`)
// This query doesn't do the count and is much faster
$albums = qu("SELECT DISTINCT(`album`), '' AS `total`
- FROM `photo` USE INDEX (`uid_album_created`)
+ FROM `photo`
WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' $sql_extra
GROUP BY `album` ORDER BY `created` DESC",
intval($uid),
else
$order = 'DESC';
-
+ /// @todo This query is totally bad, the whole functionality has to be changed
$prvnxt = qu("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
$sql_extra ORDER BY `created` $order ",
dbesc($ph[0]['album']),