From 6d4005f984ca472b0c4e3ef87176a1cd222cf66c Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 11 Jan 2021 12:23:46 +0300 Subject: [PATCH] af_psql_trgm: 1. better debugging output 2. fix incorrect default values being used sometimes 3. remove special workaround for equal titles because trgm extension seems to be working properly for those now (tested on postgres 11) 4. code cleanup --- plugins/af_psql_trgm/init.php | 78 +++++++++++++++++++++-------------- 1 file changed, 46 insertions(+), 32 deletions(-) diff --git a/plugins/af_psql_trgm/init.php b/plugins/af_psql_trgm/init.php index 20e3981ce..a38386d5b 100644 --- a/plugins/af_psql_trgm/init.php +++ b/plugins/af_psql_trgm/init.php @@ -3,6 +3,8 @@ class Af_Psql_Trgm extends Plugin { /* @var PluginHost $host */ private $host; + private $default_similarity = 0.75; + private $default_min_length = 32; function about() { return array(1.0, @@ -37,7 +39,6 @@ class Af_Psql_Trgm extends Plugin { $host->add_hook($host::HOOK_PREFS_EDIT_FEED, $this); $host->add_hook($host::HOOK_PREFS_SAVE_FEED, $this); $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this); - } function get_js() { @@ -124,7 +125,7 @@ class Af_Psql_Trgm extends Plugin { if ($args != "prefFeeds") return; print "
extension ".__('Mark similar articles as read')."\">"; + title=\"extension ".__('Mark similar articles as read (af_psql_trgm)')."\">"; if (DB_TYPE != "pgsql") { print_error("Database type not supported."); @@ -132,17 +133,14 @@ class Af_Psql_Trgm extends Plugin { $res = $this->pdo->query("select 'similarity'::regproc"); - if (!$res->fetch()) { + if (!$res || !$res->fetch()) { print_error("pg_trgm extension not found."); } - $similarity = $this->host->get($this, "similarity"); - $min_title_length = $this->host->get($this, "min_title_length"); + $similarity = $this->host->get($this, "similarity", $this->default_similarity); + $min_title_length = $this->host->get($this, "min_title_length", $this->default_min_length); $enable_globally = $this->host->get($this, "enable_globally"); - if (!$similarity) $similarity = '0.75'; - if (!$min_title_length) $min_title_length = '32'; - print "
"; print "