further mysql/DB_TYPE related cleanup

This commit is contained in:
Andrew Dolgov 2025-04-14 15:21:10 +03:00
parent b154bc7a10
commit 7e403aae92
No known key found for this signature in database
GPG Key ID: 1A56B4FA25D4AF2A
5 changed files with 34 additions and 69 deletions

View File

@ -91,7 +91,6 @@ ENV TTRSS_XDEBUG_ENABLED=""
ENV TTRSS_XDEBUG_HOST="" ENV TTRSS_XDEBUG_HOST=""
ENV TTRSS_XDEBUG_PORT="9000" ENV TTRSS_XDEBUG_PORT="9000"
ENV TTRSS_DB_TYPE="pgsql"
ENV TTRSS_DB_HOST="db" ENV TTRSS_DB_HOST="db"
ENV TTRSS_DB_PORT="5432" ENV TTRSS_DB_PORT="5432"

View File

@ -18,13 +18,16 @@ class Config {
* *
* or config.php: * or config.php:
* *
* putenv('TTRSS_DB_TYPE=pgsql'); * putenv('TTRSS_DB_HOST=my-patroni.example.com');
* *
* note lack of quotes and spaces before and after "=". * note lack of quotes and spaces before and after "=".
* *
*/ */
/** database type: pgsql */ /** this is kept for backwards/plugin compatibility, the only supported database is PostgreSQL
*
* @deprecated could be replaced with default (and only) value: `pgsql`
*/
const DB_TYPE = "DB_TYPE"; const DB_TYPE = "DB_TYPE";
/** database server hostname */ /** database server hostname */

View File

@ -27,7 +27,7 @@ class Db {
$db_port = Config::get(Config::DB_PORT) ? ';port=' . Config::get(Config::DB_PORT) : ''; $db_port = Config::get(Config::DB_PORT) ? ';port=' . Config::get(Config::DB_PORT) : '';
$db_host = Config::get(Config::DB_HOST) ? ';host=' . Config::get(Config::DB_HOST) : ''; $db_host = Config::get(Config::DB_HOST) ? ';host=' . Config::get(Config::DB_HOST) : '';
return Config::get(Config::DB_TYPE) . ':dbname=' . Config::get(Config::DB_NAME) . $db_host . $db_port; return 'pgsql:dbname=' . Config::get(Config::DB_NAME) . $db_host . $db_port;
} }
// this really shouldn't be used unless a separate PDO connection is needed // this really shouldn't be used unless a separate PDO connection is needed

View File

@ -23,7 +23,7 @@ class Db_Migrations {
} }
function initialize(string $root_path, string $migrations_table, bool $base_is_latest = true, int $max_version_override = 0): void { function initialize(string $root_path, string $migrations_table, bool $base_is_latest = true, int $max_version_override = 0): void {
$this->base_path = "$root_path/" . Config::get(Config::DB_TYPE); $this->base_path = "$root_path/pgsql";
$this->migrations_path = $this->base_path . "/migrations"; $this->migrations_path = $this->base_path . "/migrations";
$this->migrations_table = $migrations_table; $this->migrations_table = $migrations_table;
$this->base_is_latest = $base_is_latest; $this->base_is_latest = $base_is_latest;

View File

@ -63,41 +63,22 @@ class Af_Psql_Trgm extends Plugin {
print "<p>$title</p>"; print "<p>$title</p>";
if (Config::get(Config::DB_TYPE) == "pgsql") { $sth = $this->pdo->prepare("SELECT ttrss_entries.id AS id,
$sth = $this->pdo->prepare("SELECT ttrss_entries.id AS id, feed_id,
feed_id, ttrss_entries.title AS title,
ttrss_entries.title AS title, updated, link,
updated, link, ttrss_feeds.title AS feed_title,
ttrss_feeds.title AS feed_title, SIMILARITY(ttrss_entries.title, :title) AS sm
SIMILARITY(ttrss_entries.title, :title) AS sm FROM
FROM ttrss_entries, ttrss_user_entries LEFT JOIN ttrss_feeds ON (ttrss_feeds.id = feed_id)
ttrss_entries, ttrss_user_entries LEFT JOIN ttrss_feeds ON (ttrss_feeds.id = feed_id) WHERE
WHERE ttrss_entries.id = ref_id AND
ttrss_entries.id = ref_id AND ttrss_user_entries.owner_uid = :owner_uid AND
ttrss_user_entries.owner_uid = :owner_uid AND ttrss_entries.id != :id AND
ttrss_entries.id != :id AND date_entered >= NOW() - INTERVAL '2 weeks'
date_entered >= NOW() - INTERVAL '2 weeks' ORDER BY
ORDER BY sm DESC, date_entered DESC
sm DESC, date_entered DESC LIMIT 10");
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->execute(['title' => $title, "owner_uid" => $owner_uid, "id" => $id]); $sth->execute(['title' => $title, "owner_uid" => $owner_uid, "id" => $id]);
@ -157,12 +138,10 @@ class Af_Psql_Trgm extends Plugin {
title="<i class='material-icons'>extension</i> <?= __('Mark similar articles as read (af_psql_trgm)') ?>"> title="<i class='material-icons'>extension</i> <?= __('Mark similar articles as read (af_psql_trgm)') ?>">
<?php <?php
if (Config::get(Config::DB_TYPE) == "pgsql") { $res = $this->pdo->query("select 'similarity'::regproc");
$res = $this->pdo->query("select 'similarity'::regproc");
if (!$res || !$res->fetch()) { if (!$res || !$res->fetch()) {
print_error("pg_trgm extension not found."); print_error("pg_trgm extension not found.");
}
} ?> } ?>
<form dojoType="dijit.form.Form"> <form dojoType="dijit.form.Form">
@ -190,11 +169,7 @@ class Af_Psql_Trgm extends Plugin {
name="similarity" value="<?= htmlspecialchars($similarity) ?>"> name="similarity" value="<?= htmlspecialchars($similarity) ?>">
<div dojoType='dijit.Tooltip' connectId='psql_trgm_similarity' position='below'> <div dojoType='dijit.Tooltip' connectId='psql_trgm_similarity' position='below'>
<?php if (Config::get(Config::DB_TYPE) == "pgsql") { ?> <?= __("PostgreSQL trigram extension returns string similarity as a floating point number (0-1). Setting it too low might produce false positives, zero disables checking.") ?>
<?= __("PostgreSQL trigram extension returns string similarity as a floating point number (0-1). Setting it too low might produce false positives, zero disables checking.") ?>
<?php } else { ?>
<?= __("Setting this value too low might produce false positives, zero disables checking.") ?>
<?php } ?>
</div> </div>
</fieldset> </fieldset>
@ -283,10 +258,8 @@ class Af_Psql_Trgm extends Plugin {
function hook_article_filter($article) { function hook_article_filter($article) {
if (Config::get(Config::DB_TYPE) == "pgsql") { $res = $this->pdo->query("select 'similarity'::regproc");
$res = $this->pdo->query("select 'similarity'::regproc"); if (!$res || !$res->fetch()) return $article;
if (!$res || !$res->fetch()) return $article;
}
$enable_globally = $this->host->get($this, "enable_globally"); $enable_globally = $this->host->get($this, "enable_globally");
@ -336,21 +309,11 @@ class Af_Psql_Trgm extends Plugin {
return $article; return $article;
} */ } */
if (Config::get(Config::DB_TYPE) == "pgsql") { $sth = $this->pdo->prepare("SELECT MAX(SIMILARITY(title, :title)) AS ms
$sth = $this->pdo->prepare("SELECT MAX(SIMILARITY(title, :title)) AS ms FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id AND
FROM ttrss_entries, ttrss_user_entries WHERE ref_id = id AND date_entered >= NOW() - interval '1 day' AND
date_entered >= NOW() - interval '1 day' AND guid != :guid AND
guid != :guid AND owner_uid = :uid");
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->execute(['title' => $title_escaped, 'guid' => $entry_guid, 'uid' => $owner_uid]); $sth->execute(['title' => $title_escaped, 'guid' => $entry_guid, 'uid' => $owner_uid]);