Add option to flush all unread items after X days, default 45 days (avoid very large database)

This commit is contained in:
Frédéric Guillot 2014-12-15 20:38:35 -05:00
parent 5e0e079afa
commit 4313909052
14 changed files with 57 additions and 8 deletions

View File

@ -119,7 +119,8 @@ Router\get_action('config', function() {
'values' => Model\Config\get_all() + array('csrf' => Model\Config\generate_csrf()), 'values' => Model\Config\get_all() + array('csrf' => Model\Config\generate_csrf()),
'languages' => Model\Config\get_languages(), 'languages' => Model\Config\get_languages(),
'timezones' => Model\Config\get_timezones(), 'timezones' => Model\Config\get_timezones(),
'autoflush_options' => Model\Config\get_autoflush_options(), 'autoflush_read_options' => Model\Config\get_autoflush_read_options(),
'autoflush_unread_options' => Model\Config\get_autoflush_unread_options(),
'paging_options' => Model\Config\get_paging_options(), 'paging_options' => Model\Config\get_paging_options(),
'theme_options' => Model\Config\get_themes(), 'theme_options' => Model\Config\get_themes(),
'sorting_options' => Model\Config\get_sorting_directions(), 'sorting_options' => Model\Config\get_sorting_directions(),

View File

@ -9,7 +9,8 @@ use PicoFarad\Template;
// Display unread items // Display unread items
Router\get_action('unread', function() { Router\get_action('unread', function() {
Model\Item\autoflush(); Model\Item\autoflush_read();
Model\Item\autoflush_unread();
$order = Request\param('order', 'updated'); $order = Request\param('order', 'updated');
$direction = Request\param('direction', Model\Config\get('items_sorting_direction')); $direction = Request\param('direction', Model\Config\get('items_sorting_direction'));

View File

@ -31,5 +31,6 @@ if ($update_interval !== null && $call_interval !== null && $limit === Model\Fee
} }
Model\Feed\refresh_all($limit); Model\Feed\refresh_all($limit);
Model\Item\autoflush(); Model\Item\autoflush_read();
Model\Item\autoflush_unread();
Model\Config\write_debug(); Model\Config\write_debug();

View File

@ -215,4 +215,5 @@ return array(
// 'Default' => '', // 'Default' => '',
// 'Value required' => '', // 'Value required' => '',
// 'Must be an integer' => '', // 'Must be an integer' => '',
// 'Remove automatically unread items' => '',
); );

View File

@ -215,4 +215,5 @@ return array(
'Default' => 'Standard', 'Default' => 'Standard',
'Value required' => 'Wert ist erforderlich', 'Value required' => 'Wert ist erforderlich',
'Must be an integer' => 'Muss eine Ganzzahl sein', 'Must be an integer' => 'Muss eine Ganzzahl sein',
// 'Remove automatically unread items' => '',
); );

View File

@ -215,4 +215,5 @@ return array(
// 'Default' => '', // 'Default' => '',
// 'Value required' => '', // 'Value required' => '',
// 'Must be an integer' => '', // 'Must be an integer' => '',
// 'Remove automatically unread items' => '',
); );

View File

@ -215,4 +215,5 @@ return array(
'Default' => 'Défaut', 'Default' => 'Défaut',
'Value required' => 'Value required', 'Value required' => 'Value required',
'Must be an integer' => 'Must be an integer', 'Must be an integer' => 'Must be an integer',
'Remove automatically unread items' => 'Supprimer automatiquement les éléments non lus',
); );

View File

@ -215,4 +215,5 @@ return array(
// 'Default' => '', // 'Default' => '',
// 'Value required' => '', // 'Value required' => '',
// 'Must be an integer' => '', // 'Must be an integer' => '',
// 'Remove automatically unread items' => '',
); );

View File

@ -215,4 +215,5 @@ return array(
// 'Default' => '', // 'Default' => '',
// 'Value required' => '', // 'Value required' => '',
// 'Must be an integer' => '', // 'Must be an integer' => '',
// 'Remove automatically unread items' => '',
); );

View File

@ -215,4 +215,5 @@ return array(
// 'Default' => '', // 'Default' => '',
// 'Value required' => '', // 'Value required' => '',
// 'Must be an integer' => '', // 'Must be an integer' => '',
// 'Remove automatically unread items' => '',
); );

View File

@ -9,7 +9,7 @@ use PicoDb\Database;
use PicoFeed\Config as ReaderConfig; use PicoFeed\Config as ReaderConfig;
use PicoFeed\Logging; use PicoFeed\Logging;
const DB_VERSION = 29; const DB_VERSION = 30;
const HTTP_USER_AGENT = 'Miniflux (http://miniflux.net)'; const HTTP_USER_AGENT = 'Miniflux (http://miniflux.net)';
// Get PicoFeed config // Get PicoFeed config
@ -121,8 +121,8 @@ function get_display_mode()
); );
} }
// Autoflush choices for items // Autoflush choices for read items
function get_autoflush_options() function get_autoflush_read_options()
{ {
return array( return array(
'0' => t('Never'), '0' => t('Never'),
@ -134,6 +134,18 @@ function get_autoflush_options()
); );
} }
// Autoflush choices for unread items
function get_autoflush_unread_options()
{
return array(
'0' => t('Never'),
'15' => t('After %d days', 15),
'30' => t('After %d days', 30),
'45' => t('After %d days', 45),
'60' => t('After %d days', 60),
);
}
// Number of items per pages // Number of items per pages
function get_paging_options() function get_paging_options()
{ {
@ -271,6 +283,7 @@ function get_all()
'language', 'language',
'timezone', 'timezone',
'autoflush', 'autoflush',
'autoflush_unread',
'nocontent', 'nocontent',
'items_per_page', 'items_per_page',
'theme', 'theme',
@ -293,6 +306,7 @@ function validate_modification(array $values)
new Validators\Required('username', t('The user name is required')), new Validators\Required('username', t('The user name is required')),
new Validators\MaxLength('username', t('The maximum length is 50 characters'), 50), new Validators\MaxLength('username', t('The maximum length is 50 characters'), 50),
new Validators\Required('autoflush', t('Value required')), new Validators\Required('autoflush', t('Value required')),
new Validators\Required('autoflush_unread', t('Value required')),
new Validators\Required('items_per_page', t('Value required')), new Validators\Required('items_per_page', t('Value required')),
new Validators\Integer('items_per_page', t('Must be an integer')), new Validators\Integer('items_per_page', t('Must be an integer')),
new Validators\Required('theme', t('Value required')), new Validators\Required('theme', t('Value required')),

View File

@ -381,7 +381,7 @@ function mark_feed_as_read($feed_id)
} }
// Mark all read items to removed after X days // Mark all read items to removed after X days
function autoflush() function autoflush_read()
{ {
$autoflush = (int) Config\get('autoflush'); $autoflush = (int) Config\get('autoflush');
@ -406,6 +406,23 @@ function autoflush()
} }
} }
// Mark all unread items to removed after X days
function autoflush_unread()
{
$autoflush = (int) Config\get('autoflush_unread');
if ($autoflush > 0) {
// Mark read items removed after X days
Database::get('db')
->table('items')
->eq('bookmark', 0)
->eq('status', 'unread')
->lt('updated', strtotime('-'.$autoflush.'day'))
->save(array('status' => 'removed', 'content' => ''));
}
}
// Update all items // Update all items
function update_all($feed_id, array $items, $enable_grabber = false) function update_all($feed_id, array $items, $enable_grabber = false)
{ {

View File

@ -5,6 +5,11 @@ namespace Schema;
use PDO; use PDO;
use Model\Config; use Model\Config;
function version_30($pdo)
{
$pdo->exec('ALTER TABLE config ADD COLUMN autoflush_unread INTEGER DEFAULT 45');
}
function version_29($pdo) function version_29($pdo)
{ {
$pdo->exec('ALTER TABLE config ADD COLUMN fever_token INTEGER DEFAULT "'.substr(Config\generate_token(), 0, 8).'"'); $pdo->exec('ALTER TABLE config ADD COLUMN fever_token INTEGER DEFAULT "'.substr(Config\generate_token(), 0, 8).'"');

View File

@ -28,7 +28,10 @@
<?= Helper\form_select('language', $languages, $values, $errors) ?><br/> <?= Helper\form_select('language', $languages, $values, $errors) ?><br/>
<?= Helper\form_label(t('Remove automatically read items'), 'autoflush') ?> <?= Helper\form_label(t('Remove automatically read items'), 'autoflush') ?>
<?= Helper\form_select('autoflush', $autoflush_options, $values, $errors) ?><br/> <?= Helper\form_select('autoflush', $autoflush_read_options, $values, $errors) ?><br/>
<?= Helper\form_label(t('Remove automatically unread items'), 'autoflush_unread') ?>
<?= Helper\form_select('autoflush_unread', $autoflush_unread_options, $values, $errors) ?><br/>
<?= Helper\form_label(t('Items per page'), 'items_per_page') ?> <?= Helper\form_label(t('Items per page'), 'items_per_page') ?>
<?= Helper\form_select('items_per_page', $paging_options, $values, $errors) ?><br/> <?= Helper\form_select('items_per_page', $paging_options, $values, $errors) ?><br/>