From 82c00660e099070cf4dee8de82c2023d1232ef8d Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 17 Jan 2013 23:20:40 +0100 Subject: [PATCH] Preloading of items in the cache when receiving them. --- include/conversation.php | 2 +- include/items.php | 21 +++++++++++++++------ include/tags.php | 10 +++++++++- include/text.php | 4 +++- mod/item.php | 9 +++++++++ object/Item.php | 2 +- 6 files changed, 38 insertions(+), 10 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index 7665342739..7c4e606a72 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -524,7 +524,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { $hashtags = array(); $mentions = array(); - $taglist = q("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d)", + $taglist = q("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d) ORDER BY `tid`", intval(TERM_OBJ_POST), intval($item['id']), intval(TERM_HASHTAG), intval(TERM_MENTION)); foreach($taglist as $tag) { diff --git a/include/items.php b/include/items.php index b93f56e179..3779126840 100755 --- a/include/items.php +++ b/include/items.php @@ -6,6 +6,7 @@ require_once('include/salmon.php'); require_once('include/crypto.php'); require_once('include/Photo.php'); require_once('include/tags.php'); +require_once('include/text.php'); function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) { @@ -238,7 +239,7 @@ function construct_activity_object($item) { $r->link = str_replace('&','&', $r->link); $r->link = preg_replace('/\/','',$r->link); $o .= $r->link; - } + } else $o .= '' . "\r\n"; } @@ -270,7 +271,7 @@ function construct_activity_target($item) { $r->link = str_replace('&','&', $r->link); $r->link = preg_replace('/\/','',$r->link); $o .= $r->link; - } + } else $o .= '' . "\r\n"; } @@ -882,7 +883,7 @@ function item_store($arr,$force_parent = false) { $arr['gravity'] = 0; elseif(activity_match($arr['verb'],ACTIVITY_POST)) $arr['gravity'] = 6; - else + else $arr['gravity'] = 6; // extensible catchall if(! x($arr,'type')) @@ -1072,10 +1073,9 @@ function item_store($arr,$force_parent = false) { if(count($r)) { $current_post = $r[0]['id']; - create_tags_from_item($r[0]['id']); logger('item_store: created item ' . $current_post); - } - else { + create_tags_from_item($r[0]['id']); + } else { logger('item_store: could not locate created item'); return 0; } @@ -1153,6 +1153,15 @@ function item_store($arr,$force_parent = false) { tag_deliver($arr['uid'],$current_post); + // Store the fresh generated item into the cache + $cachefile = get_cachefile($arr["guid"]."-".hash("md5", $arr['body'])); + + if (($cachefile != '') AND !file_exists($cachefile)) { + $s = prepare_text($arr['body']); + file_put_contents($cachefile, $s); + logger('item_store: put item '.$current_post.' into cachefile '.$cachefile); + } + return $current_post; } diff --git a/include/tags.php b/include/tags.php index 6a5728a9ba..b02adc3d83 100644 --- a/include/tags.php +++ b/include/tags.php @@ -25,7 +25,7 @@ function create_tags_from_item($itemid) { $searchpath = $a->get_baseurl()."/search?tag="; - $messages = q("SELECT `uri`, `uid`, `id`, `created`, `edited`, `commented`, `received`, `changed`, `deleted`, `title`, `body`, `tag` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid)); + $messages = q("SELECT `guid`, `uid`, `id`, `edited`, `deleted`, `title`, `body`, `tag` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid)); if (!$messages) return; @@ -42,6 +42,14 @@ function create_tags_from_item($itemid) { if ($message["deleted"]) return; + $cachefile = get_cachefile($message["guid"]."-".hash("md5", $message['body'])); + + if (($cachefile != '') AND !file_exists($cachefile)) { + $s = prepare_text($message['body']); + file_put_contents($cachefile, $s); + logger('create_tags_from_item: put item '.$message["id"].' into cachefile '.$cachefile); + } + $taglist = explode(",", $message["tag"]); $tags = ""; diff --git a/include/text.php b/include/text.php index 5b64ef2f94..54c9f39fa6 100644 --- a/include/text.php +++ b/include/text.php @@ -1019,7 +1019,8 @@ function prepare_body($item,$attach = false) { $a = get_app(); call_hooks('prepare_body_init', $item); - $cachefile = get_cachefile($item["guid"]."-".strtotime($item["edited"])."-".hash("crc32", $item['body'])); + //$cachefile = get_cachefile($item["guid"]."-".strtotime($item["edited"])."-".hash("crc32", $item['body'])); + $cachefile = get_cachefile($item["guid"]."-".hash("md5", $item['body'])); if (($cachefile != '')) { if (file_exists($cachefile)) @@ -1027,6 +1028,7 @@ function prepare_body($item,$attach = false) { else { $s = prepare_text($item['body']); file_put_contents($cachefile, $s); + logger('prepare_body: put item '.$item["id"].' into cachefile '.$cachefile); } } else $s = prepare_text($item['body']); diff --git a/mod/item.php b/mod/item.php index 7096239b0f..452ec8a36d 100644 --- a/mod/item.php +++ b/mod/item.php @@ -757,6 +757,15 @@ function item_post(&$a) { // 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($datarray["guid"]."-".hash("md5", $datarray['body'])); + + if (($cachefile != '') AND !file_exists($cachefile)) { + $s = prepare_text($datarray['body']); + file_put_contents($cachefile, $s); + logger('mod_item: put item '.$r[0]['id'].' into cachefile '.$cachefile); + } + if($parent) { // This item is the last leaf and gets the comment box, clear any ancestors diff --git a/object/Item.php b/object/Item.php index 648b558071..de28da4642 100644 --- a/object/Item.php +++ b/object/Item.php @@ -150,7 +150,7 @@ class Item extends BaseObject { $hashtags = array(); $mentions = array(); - $taglist = q("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d)", + $taglist = q("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d) ORDER BY `tid`", intval(TERM_OBJ_POST), intval($item['id']), intval(TERM_HASHTAG), intval(TERM_MENTION)); foreach($taglist as $tag) {