From be35798b84993383f7bc8e1489bc9d78e223af18 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 17 Jan 2010 20:08:23 +0300 Subject: [PATCH] add get_article_enclosures(); initial support for memcached --- functions.php | 46 ++++++++++++++++++++++++++++++++++++++++++---- viewfeed.js | 3 ++- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/functions.php b/functions.php index 161335c9..2c84213f 100644 --- a/functions.php +++ b/functions.php @@ -94,6 +94,11 @@ } } // If translations are enabled. + if (defined('MEMCACHE_SERVER')) { + $memcache = new Memcache; + $memcache->connect(MEMCACHE_SERVER, 11211); + } + require_once 'db-prefs.php'; require_once 'compat.php'; require_once 'errors.php'; @@ -4811,15 +4816,20 @@ print $article_content; - $result = db_query($link, "SELECT * FROM ttrss_enclosures WHERE - post_id = '$id' AND content_url != ''"); +// $result = db_query($link, "SELECT * FROM ttrss_enclosures WHERE +// post_id = '$id' AND content_url != ''"); - if (db_num_rows($result) > 0) { + $result = get_article_enclosures($link, $id); + +// if (db_num_rows($result) > 0) { + + if (count($result) > 0) { $entries_html = array(); $entries = array(); - while ($line = db_fetch_assoc($result)) { + //while ($line = db_fetch_assoc($result)) { + foreach ($result as $line) { $url = $line["content_url"]; $ctype = $line["content_type"]; @@ -6483,4 +6493,32 @@ } + function get_article_enclosures($link, $id) { + + global $memcache; + + $query = "SELECT * FROM ttrss_enclosures + WHERE post_id = '$id' AND content_url != ''"; + + $cache_id = md5($query); + + $rv = array(); + + if ($memcache && $obj = $memcache->get($cache_id)) { + print_r($obj); + $rv = $obj; + } else { + $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($cache_id, $rv, 0, 3600); + } + } + + return $rv; + } + ?> diff --git a/viewfeed.js b/viewfeed.js index 5421ebd8..15bbe9ae 100644 --- a/viewfeed.js +++ b/viewfeed.js @@ -1718,7 +1718,8 @@ function cache_inject(id, article, param) { try { if (!cache_check_param(id, param)) { debug("cache_article: miss: " + id + " [p=" + param + "]"); - + + return; if (db) { -- 2.39.5