Skip to content
This repository has been archived by the owner on Oct 10, 2019. It is now read-only.

Commit

Permalink
implemented "keep-articles-days" config option.
Browse files Browse the repository at this point in the history
  • Loading branch information
akrennmair committed Dec 20, 2008
1 parent b5872fe commit 9345e5b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changes for newsbeuter:
Improved position handling in article list (fixes #112; thanks to Isaac Good)
Fixed a lot of bugs (#102, #111, #117).
Added ability to specify a list of OPML URLs when using OPML as URL source.
Added config option "keep-articles-days" to optionally keep articles only for a limited number of days.

1.3 (2008-12-06):
Changed some internal data structures to smart pointers (stability improvement).
Expand Down
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ TODO:
- when reload is finished, the focus shall be in the current form's list
- per-feed refresh settings
- add support for interactive bookmarking plugins
- add option similar to max-items but that deletes articles older than n days
- implement mark-as-read-on-hover


Expand Down Expand Up @@ -131,3 +130,4 @@ DONE:
- use categories from OPML also when it is directly used as source
- make it possible to configure more than one opml source
- when a feed is reloaded, and the article list is updated, the show-read-items flag is reset
- add option similar to max-items but that deletes articles older than n days
1 change: 1 addition & 0 deletions doc/configcommands.dsv
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ highlight|<target> <regex> <fgcolor> [<bgcolor> [<attribute> ...]]|n/a|With this
html-renderer|<path>|internal|If set to "internal", then the internal HTML renderer will be used. Otherwise, the specified command will be executed, the HTML to be rendered will be written to the command's stdin, and the program's output will be displayed. This makes it possible to use other, external programs, such as w3m, links or lynx, to render HTML.|html-renderer "w3m -dump -T text/html"
ignore-article|<feed> <filterexpr>|n/a|If a downloaded article from <feed> matches <filterexpr>, then it is ignored and not presented to the user. This command is further explained in the "kill file" section below.|ignore-article "*" "title =~ \\"Windows\\""
include|<path>|n/a|With this command, you can include other files to be interpreted as configuration files. This is especially useful to separate your configuration into several files, e.g. key configuration, color configuration, ...|include "~/.newsbeuter/colors"
keep-articles-days|<days>|0|If set the a number greater than 0, only articles that are were published within the last <n> days are kept, and older articles are deleted. If set to 0 (default value), this option is not active.|keep-articles-days 30
macro|<macro key> <command list>|n/a|With this command, you can define a macro key and specify a list of commands that shall be executed when the macro prefix and the macro key are pressed.|macro k open ; reload ; quit
max-items|<number>|0|Set the number of articles to maximally keep per feed. If the number is set to 0, then all articles are kept.|max-items 100
notify-format|<string>|"newsbeuter: finished reload, %f unread feeds (%n unread articles total)"|Format string that is used for formatting notifications. See the chapter on format strings for more information.|notify-format "%d new articles (%n unread articles, %f unread feeds)"
Expand Down
1 change: 1 addition & 0 deletions include/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class cache {
void populate_tables();
void set_pragmas();
void delete_item(const std::tr1::shared_ptr<rss_item>& item);
void clean_old_articles();

std::string prepare_query(const char * format, ...);

Expand Down
25 changes: 24 additions & 1 deletion src/cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ cache::cache(const std::string& cachefile, configcontainer * c) : db(0),cfg(c),
populate_tables();
set_pragmas();

clean_old_articles();

// we need to manually lock all DB operations because SQLite has no explicit support for multithreading.
mtx = new mutex();
}
Expand Down Expand Up @@ -366,9 +368,13 @@ void cache::externalize_rssfeed(std::tr1::shared_ptr<rss_feed> feed, bool reset_
feed->items().erase(it, feed->items().end()); // delete entries that are too much
}

unsigned int days = cfg->get_configvalue_as_int("keep-articles-days");
time_t old_time = time(NULL) - days * 24*60*60;

// the reverse iterator is there for the sorting foo below (think about it)
for (std::vector<std::tr1::shared_ptr<rss_item> >::reverse_iterator it=feed->items().rbegin(); it != feed->items().rend(); ++it) {
update_rssitem(*it, feed->rssurl(), reset_unread);
if (days == 0 || (*it)->pubDate_timestamp() >= old_time)
update_rssitem(*it, feed->rssurl(), reset_unread);
}
sqlite3_exec(db, "END;", NULL, NULL, NULL);
}
Expand Down Expand Up @@ -840,3 +846,20 @@ std::vector<std::string> cache::get_read_item_guids() {
}
return guids;
}

void cache::clean_old_articles() {
scope_mutex lock(mtx);
int rc;

unsigned int days = cfg->get_configvalue_as_int("keep-articles-days");
if (days > 0) {
time_t old_date = time(NULL) - days*24*60*60;

std::string query(utils::strprintf("DELETE FROM rss_item WHERE pubDate < %d", old_date));
GetLogger().log(LOG_DEBUG, "cache::clean_old_articles: about to delete articles with a pubDate older than %d", old_date);
rc = sqlite3_exec(db, query.c_str(), NULL, NULL, NULL);
GetLogger().log(LOG_DEBUG, "cache::clean_old_artgicles: old article delete result: rc = %d", rc);
} else {
GetLogger().log(LOG_DEBUG, "cache::clean_old_articles, days == 0, not cleaning up anything");
}
}
1 change: 1 addition & 0 deletions src/configcontainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ configcontainer::configcontainer()
config_data["download-retries"] = configdata("1", configdata::INT);
config_data["feed-sort-order"] = configdata("none", configdata::STR);
config_data["reload-threads"] = configdata("1", configdata::INT);
config_data["keep-articles-days"] = configdata("0", configdata::INT);


/* undocumented: */
Expand Down

0 comments on commit 9345e5b

Please sign in to comment.