From cf0ec06b8c0cd7bd07fbc51ebb71f04172b67230 Mon Sep 17 00:00:00 2001 From: wn_ Date: Sun, 15 Aug 2021 21:20:15 +0000 Subject: [PATCH] Use ORM in some more parts of 'update.php'. --- update.php | 69 +++++++++++++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 37 deletions(-) diff --git a/update.php b/update.php index 079069a3b..0fe4402e3 100755 --- a/update.php +++ b/update.php @@ -30,36 +30,31 @@ $days = (int) $days; if (Config::get(Config::DB_TYPE) == "pgsql") { - $interval_query = "date_updated < NOW() - INTERVAL '$days days'"; + $interval_query = "e.date_updated < NOW() - INTERVAL '$days days'"; } else /*if (Config::get(Config::DB_TYPE) == "mysql") */ { - $interval_query = "date_updated < DATE_SUB(NOW(), INTERVAL $days DAY)"; + $interval_query = "e.date_updated < DATE_SUB(NOW(), INTERVAL $days DAY)"; } $tags_deleted = 0; - - $pdo = Db::pdo(); + $limit_part = 500; while ($limit > 0) { - $limit_part = 500; + $tags = ORM::for_table('ttrss_tags') + ->table_alias('t') + ->select('t.id') + ->join('ttrss_user_entries', ['ue.int_id', '=', 't.post_int_id'], 'ue') + ->join('ttrss_entries', ['e.id', '=', 'ue.ref_id'], 'e') + ->where_not_equal('ue.tag_cache', '') + ->where_raw($interval_query) + ->limit($limit_part) + ->find_many(); - $sth = $pdo->prepare("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 ?"); - $sth->bindValue(1, $limit_part, PDO::PARAM_INT); - $sth->execute(); + if (count($tags)) { + ORM::for_table('ttrss_tags') + ->where_id_in(array_column($tags->as_array(), 'id')) + ->delete_many(); - $ids = array(); - - while ($line = $sth->fetch()) { - array_push($ids, $line['id']); - } - - if (count($ids) > 0) { - $ids = join(",", $ids); - - $usth = $pdo->query("DELETE FROM ttrss_tags WHERE id IN ($ids)"); - $tags_deleted = $usth->rowCount(); + $tags_deleted += ORM::get_last_statement()->rowCount(); } else { break; } @@ -290,29 +285,29 @@ if (isset($options["gen-search-idx"])) { echo "Generating search index (stemming set to English)...\n"; - $res = $pdo->query("SELECT COUNT(id) AS count FROM ttrss_entries WHERE tsvector_combined IS NULL"); - $row = $res->fetch(); - $count = $row['count']; - - print "Articles to process: $count.\n"; + $count = ORM::for_table('ttrss_entries') + ->where_null('tsvector_combined') + ->count(); $limit = 500; $processed = 0; - $sth = $pdo->prepare("SELECT id, title, content FROM ttrss_entries WHERE - tsvector_combined IS NULL ORDER BY id LIMIT ?"); - $sth->execute([$limit]); + print "Articles to process: $count (will limit to $limit).\n"; + + $entries = ORM::for_table('ttrss_entries') + ->select_many('id', 'title', 'content') + ->where_null('tsvector_combined') + ->order_by_asc('id') + ->limit($limit) + ->find_many(); $usth = $pdo->prepare("UPDATE ttrss_entries SET tsvector_combined = to_tsvector('english', ?) WHERE id = ?"); while (true) { - - while ($line = $sth->fetch()) { - $tsvector_combined = mb_substr(strip_tags($line["title"] . " " . $line["content"]), 0, 1000000); - - $usth->execute([$tsvector_combined, $line['id']]); - + foreach ($entries as $entry) { + $tsvector_combined = mb_substr(strip_tags($entry->title . " " . $entry->content), 0, 1000000); + $usth->execute([$tsvector_combined, $entry->id]); $processed++; } @@ -366,7 +361,7 @@ if (isset($options["user-list"])) { $users = ORM::for_table('ttrss_users') - ->order_by_expr('id') + ->order_by_asc('id') ->find_many(); foreach ($users as $user) {