Permalink
Browse files

Fix cache purges, add some more warnings when creating cache tables. …

…Closes #302
  • Loading branch information...
1 parent 6ddac32 commit c1bdffd30bd88da216c825dca510a321947245fe @ifsnop ifsnop committed Mar 15, 2016
Showing with 10 additions and 4 deletions.
  1. +3 −1 db.sql
  2. +7 −3 library/SimplePie/Cache/MySQL.php
View
@@ -17,6 +17,8 @@ CREATE INDEX feed_id ON items(feed_id);
/* MySQL */
+--- Don't paste this to create tables, since SimplePie will create
+--- tables by its own.
CREATE TABLE `cache_data` (
`id` TEXT CHARACTER SET utf8 NOT NULL,
`items` SMALLINT NOT NULL DEFAULT 0,
@@ -30,7 +32,7 @@ CREATE TABLE `cache_data` (
CREATE TABLE `items` (
`feed_id` TEXT CHARACTER SET utf8 NOT NULL,
`id` TEXT CHARACTER SET utf8 NOT NULL,
- `data` MEDIUMBLOB CHARACTER SET utf8 NOT NULL,
+ `data` MEDIUMBLOB NOT NULL,
`posted` INT UNSIGNED NOT NULL,
INDEX `feed_id` (
`feed_id`(125)
@@ -132,16 +132,20 @@ public function __construct($location, $name, $type)
$query = $this->mysql->exec('CREATE TABLE `' . $this->options['extras']['prefix'] . 'cache_data` (`id` TEXT CHARACTER SET utf8 NOT NULL, `items` SMALLINT NOT NULL DEFAULT 0, `data` BLOB NOT NULL, `mtime` INT UNSIGNED NOT NULL, UNIQUE (`id`(125)))');
if ($query === false)
{
+ trigger_error("Can't create " . $this->options['extras']['prefix'] . "cache_data table, check permissions", E_USER_WARNING);
$this->mysql = null;
+ return;
}
}
if (!in_array($this->options['extras']['prefix'] . 'items', $db))
{
- $query = $this->mysql->exec('CREATE TABLE `' . $this->options['extras']['prefix'] . 'items` (`feed_id` TEXT CHARACTER SET utf8 NOT NULL, `id` TEXT CHARACTER SET utf8 NOT NULL, `data` MEDIUMBLOB CHARACTER SET utf8 NOT NULL, `posted` INT UNSIGNED NOT NULL, INDEX `feed_id` (`feed_id`(125)))');
+ $query = $this->mysql->exec('CREATE TABLE `' . $this->options['extras']['prefix'] . 'items` (`feed_id` TEXT CHARACTER SET utf8 NOT NULL, `id` TEXT CHARACTER SET utf8 NOT NULL, `data` MEDIUMBLOB NOT NULL, `posted` INT UNSIGNED NOT NULL, INDEX `feed_id` (`feed_id`(125)))');
if ($query === false)
{
+ trigger_error("Can't create " . $this->options['extras']['prefix'] . "items table, check permissions", E_USER_WARNING);
$this->mysql = null;
+ return;
}
}
}
@@ -161,8 +165,8 @@ public function save($data)
$query = $this->mysql->prepare('DELETE i, cd FROM `' . $this->options['extras']['prefix'] . 'cache_data` cd, ' .
'`' . $this->options['extras']['prefix'] . 'items` i ' .
- 'WHERE `cd.id` = `i.feed_id` ' .
- 'AND `cd.mtime` < (unix_timestamp() - :purge_time)');
+ 'WHERE cd.id = i.feed_id ' .
+ 'AND cd.mtime < (unix_timestamp() - :purge_time)');
$query->bindValue(':purge_time', $this->options['extras']['cache_purge_time']);
if (!$query->execute())

0 comments on commit c1bdffd

Please sign in to comment.