summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2022-06-19 14:55:22 +0300
committerAndrew Dolgov <[email protected]>2022-06-19 14:55:22 +0300
commitd44db02017748c30fc06a91de4c00060e3ee4e29 (patch)
tree70a047a40d28892ddf49b2756f716ff76f6729e7
parenta4063069c88d5b45042e288212ebf3cf6f03ecaa (diff)
add mysql support
-rwxr-xr-xinit.php16
-rw-r--r--sql/mysql/schema.sql12
2 files changed, 26 insertions, 2 deletions
diff --git a/init.php b/init.php
index 27ff608..fef273b 100755
--- a/init.php
+++ b/init.php
@@ -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);