Use ORM in some more parts of 'update.php'.
This commit is contained in:
parent
73d14338ab
commit
cf0ec06b8c
69
update.php
69
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();
|
||||
|
||||
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();
|
||||
while ($limit > 0) {
|
||||
$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();
|
||||
|
||||
$ids = array();
|
||||
if (count($tags)) {
|
||||
ORM::for_table('ttrss_tags')
|
||||
->where_id_in(array_column($tags->as_array(), 'id'))
|
||||
->delete_many();
|
||||
|
||||
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) {
|
||||
|
|
Loading…
Reference in New Issue