More transactions, more queries on uncommitted data

This commit is contained in:
Michael Vogel 2016-10-24 08:10:27 +00:00
parent 47b8975bb6
commit 8cab3b5592
6 changed files with 67 additions and 29 deletions

View file

@ -670,6 +670,12 @@ class Photo {
dbesc($deny_gid)
);
}
// Update the cached values
if ($album != 'Contact Photos') {
photo_albums($uid, true);
}
return $r;
}
}}
@ -1059,3 +1065,23 @@ function store_photo($a, $uid, $imagedata = "", $url = "") {
return($image);
}
function photo_albums($uid, $update = false) {
$sql_extra = permissions_sql($uid);
$key = "photo_albums:".$uid.":".local_user().":".remote_user();
$albums = Cache::get($key);
if (is_null($albums) OR $update) {
/// @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`)
WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' $sql_extra
GROUP BY `album` ORDER BY `created` DESC",
intval($uid),
dbesc('Contact Photos'),
dbesc(t('Contact Photos'))
);
Cache::set($key, $albums, CACHE_DAY);
}
return $albums;
}

View file

@ -134,6 +134,8 @@ function cron_run(&$argv, &$argc){
} else {
proc_run(PRIORITY_LOW, 'include/dbclean.php');
}
cron_update_photo_albums();
}
// Clear cache entries
@ -155,6 +157,19 @@ function cron_run(&$argv, &$argc){
return;
}
/**
* @brief Update the cached values for the number of photo albums per user
*/
function cron_update_photo_albums() {
$r = q("SELECT `uid` FROM `user` WHERE NOT `account_expired` AND NOT `account_removed`");
if (!dbm::is_result($r))
return;
foreach ($r AS $user) {
photo_albums($user['uid'], true);
}
}
/**
* @brief Expire and remove user entries
*/

View file

@ -770,6 +770,7 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
logger('item_store: ' . print_r($arr,true), LOGGER_DATA);
q("COMMIT");
q("START TRANSACTION;");
$r = dbq("INSERT INTO `item` (`"