summaryrefslogtreecommitdiff
path: root/classes/feeds.php
diff options
context:
space:
mode:
Diffstat (limited to 'classes/feeds.php')
-rwxr-xr-xclasses/feeds.php82
1 files changed, 25 insertions, 57 deletions
diff --git a/classes/feeds.php b/classes/feeds.php
index 002a9eae7..68619302f 100755
--- a/classes/feeds.php
+++ b/classes/feeds.php
@@ -49,12 +49,6 @@ class Feeds extends Handler_Protected {
const NEVER_GROUP_FEEDS = [ Feeds::FEED_RECENTLY_READ, Feeds::FEED_ARCHIVED ];
const NEVER_GROUP_BY_DATE = [ Feeds::FEED_PUBLISHED, Feeds::FEED_STARRED, Feeds::FEED_FRESH ];
- /** @var int|float int on 64-bit, float on 32-bit */
- private $viewfeed_timestamp;
-
- /** @var int|float int on 64-bit, float on 32-bit */
- private $viewfeed_timestamp_last;
-
function csrf_ignore(string $method): bool {
$csrf_ignored = array("index");
@@ -71,7 +65,7 @@ class Feeds extends Handler_Protected {
$disable_cache = false;
- $this->_mark_timestamp("init");
+ $scope = Tracer::start(__METHOD__, [], func_get_args());
$reply = [];
$rgba_cache = [];
@@ -157,8 +151,6 @@ class Feeds extends Handler_Protected {
$qfh_ret = $this->_get_headlines($params);
}
- $this->_mark_timestamp("db query");
-
$vfeed_group_enabled = get_pref(Prefs::VFEED_GROUP_BY_FEED) &&
!(in_array($feed, self::NEVER_GROUP_FEEDS) && !$cat_view);
@@ -176,6 +168,8 @@ class Feeds extends Handler_Protected {
$reply['search_query'] = [$search, $search_language];
$reply['vfeed_group_enabled'] = $vfeed_group_enabled;
+ $p_scope = Tracer::start('plugin_menu_items');
+
$plugin_menu_items = "";
PluginHost::getInstance()->chain_hooks_callback(PluginHost::HOOK_HEADLINE_TOOLBAR_SELECT_MENU_ITEM2,
function ($result) use (&$plugin_menu_items) {
@@ -208,13 +202,15 @@ class Feeds extends Handler_Protected {
},
$feed, $cat_view, $qfh_ret);
- $this->_mark_timestamp("object header");
+ $p_scope->close();
+
+ $a_scope = Tracer::start('articles');
$headlines_count = 0;
if ($result instanceof PDOStatement) {
while ($line = $result->fetch(PDO::FETCH_ASSOC)) {
- $this->_mark_timestamp("article start: " . $line["id"] . " " . $line["title"]);
+ $aa_scope = Tracer::start('article', ['id' => $line['id']]);
++$headlines_count;
@@ -232,8 +228,6 @@ class Feeds extends Handler_Protected {
$line, $max_excerpt_length);
}
- $this->_mark_timestamp(" hook_query_headlines");
-
$id = $line["id"];
// frontend doesn't expect pdo returning booleans as strings on mysql
@@ -281,8 +275,6 @@ class Feeds extends Handler_Protected {
array_push($topmost_article_ids, $id);
}
- $this->_mark_timestamp(" labels");
-
$line["feed_title"] = $line["feed_title"] ?? "";
$button_doc = new DOMDocument();
@@ -312,6 +304,7 @@ class Feeds extends Handler_Protected {
$line);
$line["buttons"] = "";
+
PluginHost::getInstance()->chain_hooks_callback(PluginHost::HOOK_ARTICLE_BUTTON,
function ($result, $plugin) use (&$line, &$button_doc) {
if ($result && $button_doc->loadXML($result)) {
@@ -335,13 +328,9 @@ class Feeds extends Handler_Protected {
},
$line);
- $this->_mark_timestamp(" pre-sanitize");
-
$line["content"] = Sanitizer::sanitize($line["content"],
$line['hide_images'], null, $line["site_url"], $highlight_words, $line["id"]);
- $this->_mark_timestamp(" sanitize");
-
if (!get_pref(Prefs::CDM_EXPANDED)) {
$line["cdm_excerpt"] = "<span class='collapse'>
<i class='material-icons' onclick='return Article.cdmUnsetActive(event)'
@@ -352,8 +341,6 @@ class Feeds extends Handler_Protected {
}
}
- $this->_mark_timestamp(" pre-enclosures");
-
if ($line["num_enclosures"] > 0) {
$line["enclosures"] = Article::_format_enclosures($id,
sql_bool_to_bool($line["always_display_enclosures"]),
@@ -363,16 +350,12 @@ class Feeds extends Handler_Protected {
$line["enclosures"] = [ 'formatted' => '', 'entries' => [] ];
}
- $this->_mark_timestamp(" enclosures");
-
$line["updated_long"] = TimeHelper::make_local_datetime($line["updated"],true);
$line["updated"] = TimeHelper::make_local_datetime($line["updated"], false, null, false, true);
$line['imported'] = T_sprintf("Imported at %s",
TimeHelper::make_local_datetime($line["date_entered"], false));
- $this->_mark_timestamp(" local-datetime");
-
if ($line["tag_cache"])
$tags = explode(",", $line["tag_cache"]);
else
@@ -382,14 +365,12 @@ class Feeds extends Handler_Protected {
//$line["tags"] = Article::_get_tags($line["id"], false, $line["tag_cache"]);
- $this->_mark_timestamp(" tags");
-
$line['has_icon'] = self::_has_icon($feed_id);
//setting feed headline background color, needs to change text color based on dark/light
$fav_color = $line['favicon_avg_color'] ?? false;
- $this->_mark_timestamp(" pre-color");
+ $c_scope = Tracer::start('colors');
require_once "colors.php";
@@ -405,22 +386,16 @@ class Feeds extends Handler_Protected {
$line['feed_bg_color'] = 'rgba(' . implode(",", $rgba_cache[$feed_id]) . ',0.3)';
}
- $this->_mark_timestamp(" color");
- $this->_mark_timestamp(" pre-hook_render_cdm");
+ $c_scope->close();
PluginHost::getInstance()->chain_hooks_callback(PluginHost::HOOK_RENDER_ARTICLE_CDM,
function ($result, $plugin) use (&$line) {
$line = $result;
- $this->_mark_timestamp(" hook: " . get_class($plugin));
},
$line);
- $this->_mark_timestamp(" hook_render_cdm");
-
$line['content'] = DiskCache::rewrite_urls($line['content']);
- $this->_mark_timestamp(" disk_cache_rewrite");
-
/* we don't need those */
foreach (["date_entered", "guid", "last_published", "last_marked", "tag_cache", "favicon_avg_color",
@@ -429,11 +404,11 @@ class Feeds extends Handler_Protected {
array_push($reply['content'], $line);
- $this->_mark_timestamp("article end");
+ $aa_scope->close();
}
}
- $this->_mark_timestamp("end of articles");
+ $a_scope->close();
if (!$headlines_count) {
@@ -494,7 +469,7 @@ class Feeds extends Handler_Protected {
}
}
- $this->_mark_timestamp("end");
+ $scope->close();
return array($topmost_article_ids, $headlines_count, $feed, $disable_cache, $reply);
}
@@ -987,6 +962,7 @@ class Feeds extends Handler_Protected {
* @throws PDOException
*/
static function _get_counters($feed, bool $is_cat = false, bool $unread_only = false, ?int $owner_uid = null): int {
+ $scope = Tracer::start(__METHOD__, [], func_get_args());
$n_feed = (int) $feed;
$need_entries = false;
@@ -1010,11 +986,14 @@ class Feeds extends Handler_Protected {
$handler = PluginHost::getInstance()->get_feed_handler($feed_id);
if (implements_interface($handler, 'IVirtualFeed')) {
/** @var IVirtualFeed $handler */
+ $scope->close();
return $handler->get_unread($feed_id);
} else {
+ $scope->close();
return 0;
}
} else if ($n_feed == Feeds::FEED_RECENTLY_READ) {
+ $scope->close();
return 0;
// tags
} else if ($feed != "0" && $n_feed == 0) {
@@ -1028,6 +1007,7 @@ class Feeds extends Handler_Protected {
$row = $sth->fetch();
// Handle 'SUM()' returning null if there are no results
+ $scope->close();
return $row["count"] ?? 0;
} else if ($n_feed == Feeds::FEED_STARRED) {
@@ -1061,6 +1041,7 @@ class Feeds extends Handler_Protected {
$label_id = Labels::feed_to_label_id($feed);
+ $scope->close();
return self::_get_label_unread($label_id, $owner_uid);
}
@@ -1080,6 +1061,7 @@ class Feeds extends Handler_Protected {
$sth->execute([$owner_uid]);
$row = $sth->fetch();
+ $scope->close();
return $row["unread"];
} else {
@@ -1092,6 +1074,7 @@ class Feeds extends Handler_Protected {
$sth->execute([$feed, $owner_uid]);
$row = $sth->fetch();
+ $scope->close();
return $row["unread"];
}
}
@@ -1489,6 +1472,8 @@ class Feeds extends Handler_Protected {
*/
static function _get_headlines($params): array {
+ $scope = Tracer::start(__METHOD__, [], func_get_args());
+
$pdo = Db::pdo();
// WARNING: due to highly dynamic nature of this query its going to quote parameters
@@ -1981,8 +1966,9 @@ class Feeds extends Handler_Protected {
$res = $pdo->query($query);
}
- return array($res, $feed_title, $feed_site_url, $last_error, $last_updated, $search_words, $first_id, $vfeed_query_part != "", $query_error_override);
+ $scope->close();
+ return array($res, $feed_title, $feed_site_url, $last_error, $last_updated, $search_words, $first_id, $vfeed_query_part != "", $query_error_override);
}
/**
@@ -2495,23 +2481,5 @@ class Feeds extends Handler_Protected {
return [$query, $skip_first_id];
}
- private function _mark_timestamp(string $label): void {
-
- if (empty($_REQUEST['timestamps']))
- return;
-
- if (!$this->viewfeed_timestamp) $this->viewfeed_timestamp = hrtime(true);
- if (!$this->viewfeed_timestamp_last) $this->viewfeed_timestamp_last = hrtime(true);
-
- $timestamp = hrtime(true);
-
- printf("[%4d ms, %4d abs] %s\n",
- ($timestamp - $this->viewfeed_timestamp_last) / 1e6,
- ($timestamp - $this->viewfeed_timestamp) / 1e6,
- $label);
-
- $this->viewfeed_timestamp_last = $timestamp;
- }
-
}