From 7e403aae92166de6e83a5ab39738ea8ffe6eb713 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 14 Apr 2025 15:21:10 +0300 Subject: further mysql/DB_TYPE related cleanup --- plugins/af_psql_trgm/init.php | 91 +++++++++++++------------------------------ 1 file changed, 27 insertions(+), 64 deletions(-) (limited to 'plugins') diff --git a/plugins/af_psql_trgm/init.php b/plugins/af_psql_trgm/init.php index 28a0ab933..5832320e8 100644 --- a/plugins/af_psql_trgm/init.php +++ b/plugins/af_psql_trgm/init.php @@ -63,41 +63,22 @@ class Af_Psql_Trgm extends Plugin { print "

$title

"; - if (Config::get(Config::DB_TYPE) == "pgsql") { - $sth = $this->pdo->prepare("SELECT ttrss_entries.id AS id, - feed_id, - ttrss_entries.title AS title, - updated, link, - ttrss_feeds.title AS feed_title, - SIMILARITY(ttrss_entries.title, :title) AS sm - FROM - ttrss_entries, ttrss_user_entries LEFT JOIN ttrss_feeds ON (ttrss_feeds.id = feed_id) - WHERE - ttrss_entries.id = ref_id AND - ttrss_user_entries.owner_uid = :owner_uid AND - ttrss_entries.id != :id AND - date_entered >= NOW() - INTERVAL '2 weeks' - ORDER BY - sm DESC, date_entered DESC - LIMIT 10"); - } else { - $sth = $this->pdo->prepare("SELECT ttrss_entries.id AS id, - feed_id, - ttrss_entries.title AS title, - updated, link, - ttrss_feeds.title AS feed_title, - (MATCH (ttrss_entries.title) AGAINST (:title) / LENGTH(ttrss_entries.title)) AS sm - FROM - ttrss_entries, ttrss_user_entries LEFT JOIN ttrss_feeds ON (ttrss_feeds.id = feed_id) - WHERE - ttrss_entries.id = ref_id AND - ttrss_user_entries.owner_uid = :owner_uid AND - ttrss_entries.id != :id AND - date_entered >= DATE_SUB(NOW(), INTERVAL 2 WEEK) - ORDER BY - sm DESC, date_entered DESC - LIMIT 10"); - } + $sth = $this->pdo->prepare("SELECT ttrss_entries.id AS id, + feed_id, + ttrss_entries.title AS title, + updated, link, + ttrss_feeds.title AS feed_title, + SIMILARITY(ttrss_entries.title, :title) AS sm + FROM + ttrss_entries, ttrss_user_entries LEFT JOIN ttrss_feeds ON (ttrss_feeds.id = feed_id) + WHERE + ttrss_entries.id = ref_id AND + ttrss_user_entries.owner_uid = :owner_uid AND + ttrss_entries.id != :id AND + date_entered >= NOW() - INTERVAL '2 weeks' + ORDER BY + sm DESC, date_entered DESC + LIMIT 10"); $sth->execute(['title' => $title, "owner_uid" => $owner_uid, "id" => $id]); @@ -157,12 +138,10 @@ class Af_Psql_Trgm extends Plugin { title="extension "> pdo->query("select 'similarity'::regproc"); + $res = $this->pdo->query("select 'similarity'::regproc"); - if (!$res || !$res->fetch()) { - print_error("pg_trgm extension not found."); - } + if (!$res || !$res->fetch()) { + print_error("pg_trgm extension not found."); } ?>
@@ -190,11 +169,7 @@ class Af_Psql_Trgm extends Plugin { name="similarity" value="">
- - - - - +
@@ -283,10 +258,8 @@ class Af_Psql_Trgm extends Plugin { function hook_article_filter($article) { - if (Config::get(Config::DB_TYPE) == "pgsql") { - $res = $this->pdo->query("select 'similarity'::regproc"); - if (!$res || !$res->fetch()) return $article; - } + $res = $this->pdo->query("select 'similarity'::regproc"); + if (!$res || !$res->fetch()) return $article; $enable_globally = $this->host->get($this, "enable_globally"); @@ -336,21 +309,11 @@ class Af_Psql_Trgm extends Plugin { return $article; } */ - if (Config::get(Config::DB_TYPE) == "pgsql") { - $sth = $this->pdo->prepare("SELECT MAX(SIMILARITY(title, :title)) AS ms - FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id AND - date_entered >= NOW() - interval '1 day' AND - guid != :guid AND - owner_uid = :uid"); - } else { - $sth = $this->pdo->prepare("SELECT (MATCH(title) AGAINST (:title) / LENGTH(title)) AS ms - FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id AND - date_entered >= DATE_SUB(NOW(), INTERVAL 1 DAY) AND - guid != :guid AND - owner_uid = :uid - ORDER BY ms DESC - LIMIT 1"); - } + $sth = $this->pdo->prepare("SELECT MAX(SIMILARITY(title, :title)) AS ms + FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id AND + date_entered >= NOW() - interval '1 day' AND + guid != :guid AND + owner_uid = :uid"); $sth->execute(['title' => $title_escaped, 'guid' => $entry_guid, 'uid' => $owner_uid]); -- cgit v1.2.3-54-g00ecf From 3c138a71a1749537680a23aca6d4181b5b2820f0 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 14 Apr 2025 15:27:58 +0300 Subject: add deprecation notice for sql_random_function() --- classes/Db.php | 1 + classes/RPC.php | 4 +--- plugins/cache_starred_images/init.php | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) (limited to 'plugins') diff --git a/classes/Db.php b/classes/Db.php index 6310d11e3..872c6b351 100644 --- a/classes/Db.php +++ b/classes/Db.php @@ -71,6 +71,7 @@ class Db { return self::$instance->pdo; } + /** @deprecated usages should be replaced with `RANDOM()` */ public static function sql_random_function(): string { return "RANDOM()"; } diff --git a/classes/RPC.php b/classes/RPC.php index bad51e4aa..031bef509 100644 --- a/classes/RPC.php +++ b/classes/RPC.php @@ -269,8 +269,6 @@ class RPC extends Handler_Protected { $updstart_thresh_qpart = 'AND (last_update_started IS NULL OR ' . Db::past_comparison_qpart('last_update_started', '<', 5, 'minute') . ')'; - $random_qpart = Db::sql_random_function(); - $pdo = Db::pdo(); // we could be invoked from public.php with no active session @@ -290,7 +288,7 @@ class RPC extends Handler_Protected { $owner_check_qpart $update_limit_qpart $updstart_thresh_qpart - ORDER BY $random_qpart LIMIT 30"; + ORDER BY RANDOM() LIMIT 30"; $res = $pdo->query($query); diff --git a/plugins/cache_starred_images/init.php b/plugins/cache_starred_images/init.php index cc1eef0dc..48c8df3db 100755 --- a/plugins/cache_starred_images/init.php +++ b/plugins/cache_starred_images/init.php @@ -59,7 +59,7 @@ class Cache_Starred_Images extends Plugin { site_url != '' AND ttrss_user_entries.owner_uid = ? AND plugin_data NOT LIKE '%starred_cache_images%' - ORDER BY ".Db::sql_random_function()." LIMIT 100"); + ORDER BY RANDOM() LIMIT 100"); if ($sth->execute([$this->host->get_owner_uid()])) { -- cgit v1.2.3-54-g00ecf From 945690fffcabfeaa30d89514a1e81ea847091507 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 14 Apr 2025 15:28:57 +0300 Subject: add some type hints --- plugins/cache_starred_images/init.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'plugins') diff --git a/plugins/cache_starred_images/init.php b/plugins/cache_starred_images/init.php index 48c8df3db..da56da00d 100755 --- a/plugins/cache_starred_images/init.php +++ b/plugins/cache_starred_images/init.php @@ -128,6 +128,7 @@ class Cache_Starred_Images extends Plugin { if ($article_id) { $entries = $xpath->query('(//img[@src])|(//video/source[@src])'); + /** @var DOMElement $entry */ foreach ($entries as $entry) { if ($entry->hasAttribute('src')) { $src = UrlHelper::rewrite_relative($site_url, $entry->getAttribute('src')); @@ -203,6 +204,7 @@ class Cache_Starred_Images extends Plugin { $xpath = new DOMXPath($doc); $entries = $xpath->query('(//img[@src])|(//video/source[@src])'); + /** @var DOMElement $entry */ foreach ($entries as $entry) { if ($entry->hasAttribute('src') && !str_starts_with($entry->getAttribute('src'), "data:")) { -- cgit v1.2.3-54-g00ecf