From 0e4a7d7a948b1cb90413d9f479426f6a9e57afa0 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 6 Jul 2012 14:37:03 +0400 Subject: [PATCH] remove memcached stuff --- classes/pref_filters.php | 8 -- classes/rpc.php | 6 -- include/functions.php | 218 +++++++++++++++------------------------ include/rssfuncs.php | 98 ++++++------------ 4 files changed, 112 insertions(+), 218 deletions(-) diff --git a/classes/pref_filters.php b/classes/pref_filters.php index c7aa54e21..ea99d56e3 100644 --- a/classes/pref_filters.php +++ b/classes/pref_filters.php @@ -402,10 +402,6 @@ class Pref_Filters extends Protected_Handler { function editSave() { - global $memcache; - - if ($memcache) $memcache->flush(); - $savemode = db_escape_string($_REQUEST["savemode"]); $reg_exp = db_escape_string(trim($_REQUEST["reg_exp"])); $filter_type = db_escape_string(trim($_REQUEST["filter_type"])); @@ -476,8 +472,6 @@ class Pref_Filters extends Protected_Handler { function remove() { - if ($memcache) $memcache->flush(); - $ids = split(",", db_escape_string($_REQUEST["ids"])); foreach ($ids as $id) { @@ -487,8 +481,6 @@ class Pref_Filters extends Protected_Handler { function add() { - if ($memcache) $memcache->flush(); - $savemode = db_escape_string($_REQUEST["savemode"]); $regexp = db_escape_string(trim($_REQUEST["reg_exp"])); $filter_type = db_escape_string(trim($_REQUEST["filter_type"])); diff --git a/classes/rpc.php b/classes/rpc.php index 86128ccfe..bf693d2a2 100644 --- a/classes/rpc.php +++ b/classes/rpc.php @@ -360,7 +360,6 @@ class RPC extends Protected_Handler { } function setArticleTags() { - global $memcache; $id = db_escape_string($_REQUEST["id"]); @@ -414,11 +413,6 @@ class RPC extends Protected_Handler { db_query($this->link, "COMMIT"); - if ($memcache) { - $obj_id = md5("TAGS:".$_SESSION["uid"].":$id"); - $memcache->delete($obj_id); - } - $tags = get_article_tags($this->link, $id); $tags_str = format_tags_string($tags, $id); $tags_str_full = join(", ", $tags); diff --git a/include/functions.php b/include/functions.php index 4b8929a05..4a1ba42e2 100644 --- a/include/functions.php +++ b/include/functions.php @@ -83,11 +83,6 @@ startup_gettext(); - if (defined('MEMCACHE_SERVER')) { - $memcache = new Memcache; - $memcache->connect(MEMCACHE_SERVER, 11211); - } - require_once 'db-prefs.php'; require_once 'version.php'; @@ -3079,8 +3074,6 @@ function get_article_tags($link, $id, $owner_uid = 0, $tag_cache = false) { - global $memcache; - $a_id = db_escape_string($id); if (!$owner_uid) $owner_uid = $_SESSION["uid"]; @@ -3093,40 +3086,34 @@ $obj_id = md5("TAGS:$owner_uid:$id"); $tags = array(); - if ($memcache && $obj = $memcache->get($obj_id)) { - $tags = $obj; - } else { - /* check cache first */ - - if ($tag_cache === false) { - $result = db_query($link, "SELECT tag_cache FROM ttrss_user_entries - WHERE ref_id = '$id' AND owner_uid = $owner_uid"); + /* check cache first */ - $tag_cache = db_fetch_result($result, 0, "tag_cache"); - } + if ($tag_cache === false) { + $result = db_query($link, "SELECT tag_cache FROM ttrss_user_entries + WHERE ref_id = '$id' AND owner_uid = $owner_uid"); - if ($tag_cache) { - $tags = explode(",", $tag_cache); - } else { + $tag_cache = db_fetch_result($result, 0, "tag_cache"); + } - /* do it the hard way */ + if ($tag_cache) { + $tags = explode(",", $tag_cache); + } else { - $tmp_result = db_query($link, $query); + /* do it the hard way */ - while ($tmp_line = db_fetch_assoc($tmp_result)) { - array_push($tags, $tmp_line["tag_name"]); - } + $tmp_result = db_query($link, $query); - /* update the cache */ + while ($tmp_line = db_fetch_assoc($tmp_result)) { + array_push($tags, $tmp_line["tag_name"]); + } - $tags_str = db_escape_string(join(",", $tags)); + /* update the cache */ - db_query($link, "UPDATE ttrss_user_entries - SET tag_cache = '$tags_str' WHERE ref_id = '$id' - AND owner_uid = $owner_uid"); - } + $tags_str = db_escape_string(join(",", $tags)); - if ($memcache) $memcache->add($obj_id, $tags, 0, 3600); + db_query($link, "UPDATE ttrss_user_entries + SET tag_cache = '$tags_str' WHERE ref_id = '$id' + AND owner_uid = $owner_uid"); } return $tags; @@ -3590,55 +3577,44 @@ function load_filters($link, $feed, $owner_uid, $action_id = false) { $filters = array(); - global $memcache; - $obj_id = md5("FILTER:$feed:$owner_uid:$action_id"); + if ($action_id) $ftype_query_part = "action_id = '$action_id' AND"; - if ($memcache && $obj = $memcache->get($obj_id)) { - - return $obj; - - } else { - - if ($action_id) $ftype_query_part = "action_id = '$action_id' AND"; - - $result = db_query($link, "SELECT reg_exp, - ttrss_filter_types.name AS name, - ttrss_filter_actions.name AS action, - inverse, - action_param, - filter_param - FROM ttrss_filters - LEFT JOIN ttrss_feeds ON (ttrss_feeds.id = '$feed'), - ttrss_filter_types,ttrss_filter_actions - WHERE - enabled = true AND - $ftype_query_part - ttrss_filters.owner_uid = $owner_uid AND - ttrss_filter_types.id = filter_type AND - ttrss_filter_actions.id = action_id AND - ((cat_filter = true AND ttrss_feeds.cat_id = ttrss_filters.cat_id) OR - (cat_filter = true AND ttrss_feeds.cat_id IS NULL AND - ttrss_filters.cat_id IS NULL) OR - (cat_filter = false AND (feed_id IS NULL OR feed_id = '$feed'))) - ORDER BY reg_exp"); + $result = db_query($link, "SELECT reg_exp, + ttrss_filter_types.name AS name, + ttrss_filter_actions.name AS action, + inverse, + action_param, + filter_param + FROM ttrss_filters + LEFT JOIN ttrss_feeds ON (ttrss_feeds.id = '$feed'), + ttrss_filter_types,ttrss_filter_actions + WHERE + enabled = true AND + $ftype_query_part + ttrss_filters.owner_uid = $owner_uid AND + ttrss_filter_types.id = filter_type AND + ttrss_filter_actions.id = action_id AND + ((cat_filter = true AND ttrss_feeds.cat_id = ttrss_filters.cat_id) OR + (cat_filter = true AND ttrss_feeds.cat_id IS NULL AND + ttrss_filters.cat_id IS NULL) OR + (cat_filter = false AND (feed_id IS NULL OR feed_id = '$feed'))) + ORDER BY reg_exp"); - while ($line = db_fetch_assoc($result)) { + while ($line = db_fetch_assoc($result)) { - if (!$filters[$line["name"]]) $filters[$line["name"]] = array(); - $filter["reg_exp"] = $line["reg_exp"]; - $filter["action"] = $line["action"]; - $filter["action_param"] = $line["action_param"]; - $filter["filter_param"] = $line["filter_param"]; - $filter["inverse"] = sql_bool_to_bool($line["inverse"]); + if (!$filters[$line["name"]]) $filters[$line["name"]] = array(); + $filter["reg_exp"] = $line["reg_exp"]; + $filter["action"] = $line["action"]; + $filter["action_param"] = $line["action_param"]; + $filter["filter_param"] = $line["filter_param"]; + $filter["inverse"] = sql_bool_to_bool($line["inverse"]); - array_push($filters[$line["name"]], $filter); - } + array_push($filters[$line["name"]], $filter); + } - if ($memcache) $memcache->add($obj_id, $filters, 0, 3600*8); - return $filters; - } + return $filters; } function get_score_pic($score) { @@ -3915,53 +3891,44 @@ } function get_article_labels($link, $id) { - global $memcache; - - $obj_id = md5("LABELS:$id:" . $_SESSION["uid"]); - $rv = array(); - if ($memcache && $obj = $memcache->get($obj_id)) { - return $obj; - } else { - $result = db_query($link, "SELECT label_cache FROM - ttrss_user_entries WHERE ref_id = '$id' AND owner_uid = " . - $_SESSION["uid"]); - - $label_cache = db_fetch_result($result, 0, "label_cache"); + $result = db_query($link, "SELECT label_cache FROM + ttrss_user_entries WHERE ref_id = '$id' AND owner_uid = " . + $_SESSION["uid"]); - if ($label_cache) { + $label_cache = db_fetch_result($result, 0, "label_cache"); - $label_cache = json_decode($label_cache, true); + if ($label_cache) { - if ($label_cache["no-labels"] == 1) - return $rv; - else - return $label_cache; - } + $label_cache = json_decode($label_cache, true); - $result = db_query($link, - "SELECT DISTINCT label_id,caption,fg_color,bg_color - FROM ttrss_labels2, ttrss_user_labels2 - WHERE id = label_id - AND article_id = '$id' - AND owner_uid = ".$_SESSION["uid"] . " - ORDER BY caption"); + if ($label_cache["no-labels"] == 1) + return $rv; + else + return $label_cache; + } - while ($line = db_fetch_assoc($result)) { - $rk = array($line["label_id"], $line["caption"], $line["fg_color"], - $line["bg_color"]); - array_push($rv, $rk); - } - if ($memcache) $memcache->add($obj_id, $rv, 0, 3600); + $result = db_query($link, + "SELECT DISTINCT label_id,caption,fg_color,bg_color + FROM ttrss_labels2, ttrss_user_labels2 + WHERE id = label_id + AND article_id = '$id' + AND owner_uid = ".$_SESSION["uid"] . " + ORDER BY caption"); - if (count($rv) > 0) - label_update_cache($link, $id, $rv); - else - label_update_cache($link, $id, array("no-labels" => 1)); + while ($line = db_fetch_assoc($result)) { + $rk = array($line["label_id"], $line["caption"], $line["fg_color"], + $line["bg_color"]); + array_push($rv, $rk); } + if (count($rv) > 0) + label_update_cache($link, $id, $rv); + else + label_update_cache($link, $id, array("no-labels" => 1)); + return $rv; } @@ -4017,13 +3984,6 @@ function label_add_article($link, $id, $label, $owner_uid) { - global $memcache; - - if ($memcache) { - $obj_id = md5("LABELS:$id:$owner_uid"); - $memcache->delete($obj_id); - } - $label_id = label_find_id($link, $label, $owner_uid); if (!$label_id) return; @@ -4047,15 +4007,8 @@ } function label_remove($link, $id, $owner_uid) { - global $memcache; - if (!$owner_uid) $owner_uid = $_SESSION["uid"]; - if ($memcache) { - $obj_id = md5("LABELS:$id:$owner_uid"); - $memcache->delete($obj_id); - } - db_query($link, "BEGIN"); $result = db_query($link, "SELECT caption FROM ttrss_labels2 @@ -4375,25 +4328,16 @@ function get_article_enclosures($link, $id) { - global $memcache; - $query = "SELECT * FROM ttrss_enclosures WHERE post_id = '$id' AND content_url != ''"; - $obj_id = md5("ENCLOSURES:$id"); - $rv = array(); - if ($memcache && $obj = $memcache->get($obj_id)) { - $rv = $obj; - } else { - $result = db_query($link, $query); + $result = db_query($link, $query); - if (db_num_rows($result) > 0) { - while ($line = db_fetch_assoc($result)) { - array_push($rv, $line); - } - if ($memcache) $memcache->add($obj_id, $rv, 0, 3600); + if (db_num_rows($result) > 0) { + while ($line = db_fetch_assoc($result)) { + array_push($rv, $line); } } diff --git a/include/rssfuncs.php b/include/rssfuncs.php index c86c36773..12c4a57d2 100644 --- a/include/rssfuncs.php +++ b/include/rssfuncs.php @@ -209,34 +209,13 @@ } } - function update_rss_feed($link, $feed, $ignore_daemon = false, $no_cache = false) { - - global $memcache; - - /* Update all feeds with the same URL to utilize memcache */ - - if ($memcache) { - $result = db_query($link, "SELECT f1.id - FROM ttrss_feeds AS f1, ttrss_feeds AS f2 - WHERE f2.feed_url = f1.feed_url AND f2.id = '$feed'"); - - while ($line = db_fetch_assoc($result)) { - update_rss_feed_real($link, $line["id"], $ignore_daemon, $no_cache); - } - } else { - update_rss_feed_real($link, $feed, $ignore_daemon, $no_cache); - } - } - - function update_rss_feed_real($link, $feed, $ignore_daemon = false, $no_cache = false, + function update_rss_feed($link, $feed, $ignore_daemon = false, $no_cache = false, $override_url = false) { require_once "lib/simplepie/simplepie.inc"; require_once "lib/magpierss/rss_fetch.inc"; require_once 'lib/magpierss/rss_utils.inc'; - global $memcache; - $debug_enabled = defined('DAEMON_EXTENDED_DEBUG') || $_REQUEST['xdebug']; if (!$_REQUEST["daemon"] && !$ignore_daemon) { @@ -334,62 +313,47 @@ _debug("update_rss_feed: fetching [$fetch_url]..."); } - $obj_id = md5("FDATA:$use_simplepie:$fetch_url"); + // Ignore cache if new feed or manual update. + $cache_age = (is_null($last_updated) || $last_updated == '1970-01-01 00:00:00') ? + -1 : get_feed_update_interval($link, $feed) * 60; - if ($memcache && $obj = $memcache->get($obj_id)) { - - if ($debug_enabled) { - _debug("update_rss_feed: data found in memcache."); - } + if ($update_method == 3) { + $rss = fetch_twitter_rss($link, $fetch_url, $owner_uid); + } else if ($update_method == 1) { - $rss = $obj; + define('MAGPIE_CACHE_AGE', $cache_age); + define('MAGPIE_CACHE_ON', !$no_cache); + define('MAGPIE_FETCH_TIME_OUT', 60); + define('MAGPIE_CACHE_DIR', CACHE_DIR . "/magpie"); + $rss = @fetch_rss($fetch_url); } else { + $simplepie_cache_dir = CACHE_DIR . "/simplepie"; - // Ignore cache if new feed or manual update. - $cache_age = (is_null($last_updated) || $last_updated == '1970-01-01 00:00:00') ? - -1 : get_feed_update_interval($link, $feed) * 60; - - if ($update_method == 3) { - $rss = fetch_twitter_rss($link, $fetch_url, $owner_uid); - } else if ($update_method == 1) { - - define('MAGPIE_CACHE_AGE', $cache_age); - define('MAGPIE_CACHE_ON', !$no_cache); - define('MAGPIE_FETCH_TIME_OUT', 60); - define('MAGPIE_CACHE_DIR', CACHE_DIR . "/magpie"); - - $rss = @fetch_rss($fetch_url); - } else { - $simplepie_cache_dir = CACHE_DIR . "/simplepie"; - - if (!is_dir($simplepie_cache_dir)) { - mkdir($simplepie_cache_dir); - } - - $rss = new SimplePie(); - $rss->set_useragent(SELF_USER_AGENT); - # $rss->set_timeout(10); - $rss->set_feed_url($fetch_url); - $rss->set_output_encoding('UTF-8'); - //$rss->force_feed(true); + if (!is_dir($simplepie_cache_dir)) { + mkdir($simplepie_cache_dir); + } - if ($debug_enabled) { - _debug("feed update interval (sec): " . - get_feed_update_interval($link, $feed)*60); - } + $rss = new SimplePie(); + $rss->set_useragent(SELF_USER_AGENT); +# $rss->set_timeout(10); + $rss->set_feed_url($fetch_url); + $rss->set_output_encoding('UTF-8'); + //$rss->force_feed(true); - $rss->enable_cache(!$no_cache); + if ($debug_enabled) { + _debug("feed update interval (sec): " . + get_feed_update_interval($link, $feed)*60); + } - if (!$no_cache) { - $rss->set_cache_location($simplepie_cache_dir); - $rss->set_cache_duration($cache_age); - } + $rss->enable_cache(!$no_cache); - $rss->init(); + if (!$no_cache) { + $rss->set_cache_location($simplepie_cache_dir); + $rss->set_cache_duration($cache_age); } - if ($memcache && $rss) $memcache->add($obj_id, $rss, 0, 300); + $rss->init(); } // print_r($rss);