]> git.wh0rd.org Git - tt-rss.git/commitdiff
optimize catchup selected, add CatchupSelected subop in viewfeed
authorAndrew Dolgov <fox@madoka.spb.ru>
Tue, 19 Sep 2006 04:14:27 +0000 (05:14 +0100)
committerAndrew Dolgov <fox@madoka.spb.ru>
Tue, 19 Sep 2006 04:14:27 +0000 (05:14 +0100)
backend-rpc.php
backend.php
db.php
functions.php

index e7b42244a9606caf37b08a37ad401a0ab787e443..6de87aa840513f953c247123c2e158f16be1c1b0 100644 (file)
                        print "</rpc-reply>";
 
                }
-       
+
                /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */
                if ($subop == "catchupSelected") {
 
                        $ids = split(",", db_escape_string($_GET["ids"]));
-
                        $cmode = sprintf("%d", $_GET["cmode"]);
 
-                       foreach ($ids as $id) {
+                       catchupArticlesById($link, $ids, $cmode);
 
-                               if ($cmode == 0) {
-                                       db_query($link, "UPDATE ttrss_user_entries SET 
-                                       unread = false,last_read = NOW()
-                                       WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
-                               } else if ($cmode == 1) {
-                                       db_query($link, "UPDATE ttrss_user_entries SET 
-                                       unread = true
-                                       WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
-                               } else {
-                                       db_query($link, "UPDATE ttrss_user_entries SET 
-                                       unread = NOT unread,last_read = NOW()
-                                       WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]);
-                               }
-                       }
                        print "<rpc-reply>";
                        print "<counters>";
                        getAllCounters($link);
index 7d13184b84ee91bbb48ec6c8dbde3614aaafd05a..4e0dfccb799fbf283c83db5e3e1403469acc33b1 100644 (file)
                                        type=\"text/css\" href=\"tt-rss_compact.css\"/>";
                }
 
+               if ($subop == "CatchupSelected") {
+                       $ids = split(",", db_escape_string($_GET["ids"]));
+                       $cmode = sprintf("%d", $_GET["cmode"]);
+
+                       catchupArticlesById($link, $ids, $cmode);
+               }
+
                if ($subop == "ForceUpdate" && sprintf("%d", $feed) > 0) {
                        update_generic_feed($link, $feed, $cat_view);
                }
diff --git a/db.php b/db.php
index 6d998bd6f907bd108c1f78b05b0470de9af39689..d8187fc3bcf65808bfe674d383fda7b19aec27d4 100644 (file)
--- a/db.php
+++ b/db.php
@@ -61,7 +61,7 @@ function db_query($link, $query, $die_on_error = true) {
                if (!$result) {
                        $query = htmlspecialchars($query); // just in case
                        if ($die_on_error) {
-                               die("Query <i>$query</i> failed: " . pg_last_error($link));                     
+                               die("Query <i>$query</i> failed [$result]: " . pg_last_error($link));                   
                        }
                }
                return $result;
index 03e511d9f848869a4b203bdf5aa9a0fa98e3c446..bb80cac57232ab90fe3657038116aad0515a0532 100644 (file)
                        }                       
                }
        }
+
+       function catchupArticlesById($link, $ids, $cmode) {
+
+               $tmp_ids = array();
+
+               foreach ($ids as $id) {
+                       array_push($tmp_ids, "ref_id = '$id'");
+               }
+
+               $ids_qpart = join(" OR ", $tmp_ids);
+
+               if ($cmode == 0) {
+                       db_query($link, "UPDATE ttrss_user_entries SET 
+                       unread = false,last_read = NOW()
+                       WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
+               } else if ($cmode == 1) {
+                       db_query($link, "UPDATE ttrss_user_entries SET 
+                       unread = true
+                       WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
+               } else {
+                       db_query($link, "UPDATE ttrss_user_entries SET 
+                       unread = NOT unread,last_read = NOW()
+                       WHERE ($ids_qpart) AND owner_uid = " . $_SESSION["uid"]);
+               }
+       }
+
 ?>