Tiny Tiny RSS: Community

Updating display with comment counts from reddit


I’ve been running tt-rss on my home server for a long time now. It works great and I love it, so I hadn’t felt the need to update for some time (cough 3 years cough).

Anyway, I git pull origin-ed yesterday and everything’s great.

Everything but my “custom” reddit comment count display. At some point, I think reddit stopped updating their feeds with number of comments a post had. At that time, I created a service (php file) that updated the ttrss_entries table with number of comments a post had via reddit’s api. I can no longer see this number

I have been looking at the code since, and, being a mediocre programmer, I am kind of confused. From what I can tell ttrss_entries.num_comments is no longer used to fill-in what is displayed as number of comments for an entry. (I am having a hard time figuring out how “headlines” ultimately get populated from backend to js).

I think I can hook into things and replicate my previous behavior (see example below).

Is HOOK_FORMAT_ARTICLE the right one to use for updating number of comments that are displayed? In experimenting with it, I can’t get HOOK_FORMAT_ARTICLE to do anything. I don’t think it’s triggering at all? I tried deleting my session from ttrss_sessions to see if that would trigger it, but it seems not.

Thanks in advance!

 class Reddit_Comments extends Plugin {

    private $host;

 // You can change the description of this plugin here
    function about() {
       return array(1.0,
          "Update reddit comments count via their api.",

	 function api_version() {
		 return 2;

    function init($host) {
       $this->host = $host;

       $host->add_hook($host::HOOK_ARTICLE_FILTER, $this);
		 $host->add_hook($host::HOOK_RENDER_ARTICLE, $this);

	function hook_article_filter($article) {
      //Call reddit api to update comment count in 

      return $article;

	function hook_render_article($article) {
      //Run sql query and change article content div to show
      //comment number from ttrss_entries??
      return $article;

there’s multiple ways to do that with their own pros and cons.

article_filter is probably not what you want, it only fires when article itself is considered updated, normally this happens once.

render_article is fired in three panel mode only, i think, if you’re using combined mode it’s not going to do anything. if you want to support three panel mode though you’ll have to implement it.

there’s some hooks related to rendering headlines, this could be what you want. however, those are called synchronously when you open feeds in the UI so processing delays could easily cause terrible UI lag. imagine updating comments somehow for 30 articles, 1 second each is 30 second UI delay.

personally in this situation i would either:

  • update counts asynchronously on frontend (javascript) side as headlines render, either calling a plugin endpoint or doing a JSONP request to reddit directly if its possible

  • use maintenance task to update comments on the backend for a subset of articles (i.e. recent ones) and store this information in the database so its rendered by the frontend without any further work, there’s a separate field for comments already which should be used by the frontend

overall i think doing this the latter way is a lot easier.

e: sorry for the delay, somehow i missed this post