]> git.wh0rd.org Git - tt-rss.git/commitdiff
make sure cleanup_tags() actually cleans stuff up
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Sat, 13 Nov 2010 17:12:19 +0000 (20:12 +0300)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Sat, 13 Nov 2010 17:12:19 +0000 (20:12 +0300)
functions.php

index 2331c89f48768f4febfa31426dcf14d3f7cb70ad..ed78158676b529ee57bac7bd4f9cbfb5c0e85a92 100644 (file)
                        $interval_query = "date_updated < DATE_SUB(NOW(), INTERVAL $days DAY)";
                }
 
-               $query = "SELECT ttrss_tags.id AS id 
-                       FROM ttrss_tags, ttrss_user_entries, ttrss_entries 
-                       WHERE post_int_id = int_id AND $interval_query AND
-                       ref_id = ttrss_entries.id AND tag_cache != '' LIMIT $limit";
+               $tags_deleted = 0;
 
-               $result = db_query($link, $query);
+               while ($limit > 0) {
+                       $limit_part = 500;
+
+                       $query = "SELECT ttrss_tags.id AS id 
+                               FROM ttrss_tags, ttrss_user_entries, ttrss_entries 
+                               WHERE post_int_id = int_id AND $interval_query AND
+                               ref_id = ttrss_entries.id AND tag_cache != '' LIMIT $limit_part";
+       
+                       $result = db_query($link, $query);
+
+                       $ids = array();
+
+                       while ($line = db_fetch_assoc($result)) {
+                               array_push($ids, $line['id']);
+                       }
+
+                       if (count($ids) > 0) {
+                               $ids = join(",", $ids);
+                               print ".";
+
+                               $tmp_result = db_query($link, "DELETE FROM ttrss_tags WHERE id IN ($ids)");
+                               $tags_deleted += db_affected_rows($link, $tmp_result);
+                       } else {
+                               break;
+                       }
+
+                       $limit -= $limit_part;
+               }
+
+               print "\n";
 
-               return db_affected_rows($link, $result);
+               return $tags_deleted;
        }
 
 ?>