diff options
author | Andrew Dolgov <[email protected]> | 2022-06-19 14:55:22 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2022-06-19 14:55:22 +0300 |
commit | d44db02017748c30fc06a91de4c00060e3ee4e29 (patch) | |
tree | 70a047a40d28892ddf49b2756f716ff76f6729e7 | |
parent | a4063069c88d5b45042e288212ebf3cf6f03ecaa (diff) |
add mysql support
-rwxr-xr-x | init.php | 16 | ||||
-rw-r--r-- | sql/mysql/schema.sql | 12 |
2 files changed, 26 insertions, 2 deletions
@@ -56,8 +56,14 @@ class Reddit_Delay extends Plugin { private function cache_cleanup() : void { $max_days = (int) Config::get(Config::CACHE_MAX_DAYS); + if (Config::get(Config::DB_TYPE) == "pgsql") { + $interval_query = "orig_ts < NOW() - INTERVAL '$max_days days'"; + } else /*if (Config::get(Config::DB_TYPE) == "mysql") */ { + $interval_query = "orig_ts < DATE_SUB(NOW(), INTERVAL $max_days DAY)"; + } + $sth = $this->pdo->prepare("DELETE FROM ttrss_plugin_reddit_delay_cache - WHERE orig_ts < NOW() - INTERVAL '$max_days days'"); + WHERE $interval_query"); $sth->execute([]); } @@ -72,9 +78,15 @@ class Reddit_Delay extends Plugin { private function cache_pull_older(int $feed_id, int $delay, DOMDocument $doc, DOMXPath $xpath) : array { $skip_removed = $this->host->get($this, "skip_removed"); + if (Config::get(Config::DB_TYPE) == "pgsql") { + $interval_query = "(orig_ts < NOW() - INTERVAL '$delay hours')"; + } else /*if (Config::get(Config::DB_TYPE) == "mysql") */ { + $interval_query = "(orig_ts < DATE_SUB(NOW(), INTERVAL $delay HOUR))"; + } + $entries = ORM::for_table('ttrss_plugin_reddit_delay_cache') ->where('feed_id', $feed_id) - ->where_raw("(orig_ts < NOW() - INTERVAL '$delay hours')") + ->where_raw($interval_query) ->find_many(); $target = $xpath->query("//atom:feed|//channel")->item(0); diff --git a/sql/mysql/schema.sql b/sql/mysql/schema.sql new file mode 100644 index 0000000..0df2d9a --- /dev/null +++ b/sql/mysql/schema.sql @@ -0,0 +1,12 @@ +drop table if exists ttrss_plugin_reddit_delay_cache; + +create table ttrss_plugin_reddit_delay_cache (id integer not null primary key auto_increment, + feed_id integer not null REFERENCES ttrss_feeds(id) on DELETE cascade, + link text not null, + item text not NULL, + orig_ts datetime not null) ENGINE=InnoDB DEFAULT CHARSET=UTF8; + +create index ttrss_plugin_reddit_delay_cache_link_idx on ttrss_plugin_reddit_delay_cache(link); +create index ttrss_plugin_reddit_delay_cache_feed_id_idx on ttrss_plugin_reddit_delay_cache(feed_id); + +create unique index ttrss_plugin_reddit_delay_cache_idx on ttrss_plugin_reddit_delay_cache(feed_id, link); |