Relocated the cache code.

This commit is contained in:
Michael Vogel 2015-02-10 08:22:21 +01:00
parent 2dc5f1aefc
commit 1a75503b1c
3 changed files with 20 additions and 22 deletions

View file

@ -1480,16 +1480,7 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa
if (!$deleted AND !$dontcache) {
// Store the fresh generated item into the cache
$cachefile = get_cachefile(urlencode($arr["guid"])."-".hash("md5", $arr['body']));
if (($cachefile != '') AND !file_exists($cachefile)) {
$s = prepare_text($arr['body']);
$a = get_app();
$stamp1 = microtime(true);
file_put_contents($cachefile, $s);
$a->save_timestamp($stamp1, "file");
logger('item_store: put item '.$current_post.' into cachefile '.$cachefile);
}
put_item_in_cache($arr);
$r = q('SELECT * FROM `item` WHERE id = %d', intval($current_post));
if (count($r) == 1) {

View file

@ -1281,6 +1281,18 @@ function redir_private_images($a, &$item) {
}}
function put_item_in_cache($item) {
$cachefile = get_cachefile(urlencode($item["guid"])."-".hash("md5", $item['body']));
if (($cachefile != '') AND !file_exists($cachefile)) {
$s = prepare_text($item['body']);
$a = get_app();
$stamp1 = microtime(true);
file_put_contents($cachefile, $s);
$a->save_timestamp($stamp1, "file");
logger('put item '.$item["guid"].' into cachefile '.$cachefile);
}
}
// Given an item array, convert the body element from bbcode to html and add smilie icons.
// If attach is true, also add icons for item attachments

View file

@ -22,6 +22,7 @@ require_once('library/langdet/Text/LanguageDetect.php');
require_once('include/tags.php');
require_once('include/files.php');
require_once('include/threads.php');
require_once('include/text.php');
function item_post(&$a) {
@ -824,21 +825,12 @@ function item_post(&$a) {
if(count($r)) {
$post_id = $r[0]['id'];
logger('mod_item: saved item ' . $post_id);
add_thread($post_id);
// update filetags in pconfig
file_tag_update_pconfig($uid,$categories_old,$categories_new,'category');
// Store the fresh generated item into the cache
$cachefile = get_cachefile(urlencode($datarray["guid"])."-".hash("md5", $datarray['body']));
if (($cachefile != '') AND !file_exists($cachefile)) {
$s = prepare_text($datarray['body']);
$stamp1 = microtime(true);
file_put_contents($cachefile, $s);
$a->save_timestamp($stamp1, "file");
logger('mod_item: put item '.$r[0]['id'].' into cachefile '.$cachefile);
}
put_item_in_cache($datarray);
if($parent) {
@ -947,7 +939,8 @@ function item_post(&$a) {
dbesc(datetime_convert()),
intval($parent)
);
update_thread($parent);
if ($post_id != $parent)
update_thread($parent);
$datarray['id'] = $post_id;
$datarray['plink'] = $a->get_baseurl().'/display/'.urlencode($datarray['guid']);
@ -990,7 +983,9 @@ function item_post(&$a) {
create_tags_from_item($post_id);
create_files_from_item($post_id);
update_thread($post_id);
if ($post_id == $parent)
add_thread($post_id);
// This is a real juggling act on shared hosting services which kill your processes
// e.g. dreamhost. We used to start delivery to our native delivery agents in the background