]> git.wh0rd.org - tt-rss.git/commitdiff
pref-feeds: check for inactive feeds asynchronously
authorAndrew Dolgov <noreply@madoka.volgo-balt.ru>
Wed, 12 Aug 2015 13:19:42 +0000 (16:19 +0300)
committerAndrew Dolgov <noreply@madoka.volgo-balt.ru>
Wed, 12 Aug 2015 13:19:42 +0000 (16:19 +0300)
classes/pref/feeds.php
js/prefs.js

index 4194eda98d6967a012cb7996eef95bbbe6a18b15..98eadf39c45ae553309684d07b6cc9c7b22cfd1e 100644 (file)
@@ -1298,30 +1298,11 @@ class Pref_Feeds extends Handler_Protected {
                                __("Feeds with errors") . "</button>";
                }
 
-               if (DB_TYPE == "pgsql") {
-                       $interval_qpart = "NOW() - INTERVAL '3 months'";
-               } else {
-                       $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)";
-               }
-
-               // could be performance-intensive and prevent feeds pref-panel from showing
-               if (!defined('_DISABLE_INACTIVE_FEEDS') || !_DISABLE_INACTIVE_FEEDS) {
-                       $result = $this->dbh->query("SELECT COUNT(*) AS num_inactive FROM ttrss_feeds WHERE
-                                       (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE
-                                               ttrss_entries.id = ref_id AND
-                                                       ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart AND
-                       ttrss_feeds.owner_uid = ".$_SESSION["uid"]);
-
-                       $num_inactive = $this->dbh->fetch_result($result, 0, "num_inactive");
-               } else {
-                       $num_inactive = 0;
-               }
-
-               if ($num_inactive > 0) {
-                       $inactive_button = "<button dojoType=\"dijit.form.Button\"
-                                       onclick=\"showInactiveFeeds()\">" .
-                                       __("Inactive feeds") . "</button>";
-               }
+               $inactive_button = "<button dojoType=\"dijit.form.Button\"
+                               id=\"pref_feeds_inactive_btn\"
+                               style=\"display : none\"
+                               onclick=\"showInactiveFeeds()\">" .
+                               __("Inactive feeds") . "</button>";
 
                $feed_search = $this->dbh->escape_string($_REQUEST["search"]);
 
@@ -1433,6 +1414,8 @@ class Pref_Feeds extends Handler_Protected {
                </script>
                <script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
                        Element.hide(\"feedlistLoading\");
+
+                       checkInactiveFeeds();
                </script>
                </div>";
 
@@ -1970,5 +1953,20 @@ class Pref_Feeds extends Handler_Protected {
                return $c;
        }
 
+       function getinactivefeeds() {
+               if (DB_TYPE == "pgsql") {
+                       $interval_qpart = "NOW() - INTERVAL '3 months'";
+               } else {
+                       $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)";
+               }
+
+               $result = $this->dbh->query("SELECT COUNT(*) AS num_inactive FROM ttrss_feeds WHERE
+                               (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE
+                                       ttrss_entries.id = ref_id AND
+                                               ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart AND
+                         ttrss_feeds.owner_uid = ".$_SESSION["uid"]);
+
+               print (int) $this->dbh->fetch_result($result, 0, "num_inactive");
+       }
 }
 ?>
index 67a4a378c57c9b1131c7027ebaf7516a1863b908..159b9ecbc3654bb9f660e2c6a93a78e6fe04231a 100644 (file)
@@ -24,6 +24,20 @@ function updateFeedList(sort_key) {
                } });
 }
 
+function checkInactiveFeeds() {
+       try {
+               new Ajax.Request("backend.php", {
+                       parameters: "?op=pref-feeds&method=getinactivefeeds",
+                       onComplete: function(transport) {
+                               if (parseInt(transport.responseText) > 0) {
+                                       Element.show(dijit.byId("pref_feeds_inactive_btn").domNode);
+                               }
+                       } });
+
+       } catch (e) {
+               exception_error("checkInactiveFeeds", e);
+       }
+}
 
 function updateUsersList(sort_key) {
        try {