summaryrefslogtreecommitdiff
path: root/update.php
diff options
context:
space:
mode:
authorwn_ <[email protected]>2021-08-15 21:20:15 +0000
committerwn_ <[email protected]>2021-08-15 21:48:50 +0000
commitcf0ec06b8c0cd7bd07fbc51ebb71f04172b67230 (patch)
tree00d433df40169f7509f6d5642ea75c5b83906d0d /update.php
parent73d14338abde1925dc11fce013a939d3704122e7 (diff)
Use ORM in some more parts of 'update.php'.
Diffstat (limited to 'update.php')
-rwxr-xr-xupdate.php73
1 files changed, 34 insertions, 39 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;
-
- $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();
-
- $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 = 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();
+
+ if (count($tags)) {
+ ORM::for_table('ttrss_tags')
+ ->where_id_in(array_column($tags->as_array(), 'id'))
+ ->delete_many();
+
+ $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) {