Skip to content

Commit 9255e05

Browse files
committed
Allow setting initial fetch size.
1 parent 8dc147e commit 9255e05

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

config.ini

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ threads = 4
1212

1313

1414
[global]
15-
; How many articles to fetch and present in each feed
16-
articles = 10
15+
; How many articles to fetch initially in each feed
16+
initial = 10
17+
; How many articles to keep in each feed
18+
articles = 30
1719
; Time between feed refreshes, in seconds
1820
refresh = 3600
1921
; Time to wait after feed refresh failure happens
@@ -27,6 +29,7 @@ apod = 1
2729

2830
; Values set in the global section may be overriden per feed
2931
[apod]
30-
;articles = 10
32+
;initial = 10
33+
;articles = 30
3134
;refresh = 3600
3235
;failure = 60

src/Apod.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ Apod::Apod()
1414

1515
bool Apod::InitializeImpl( ini_t* config )
1616
{
17+
ini_sget( config, "apod", "initial", "%d", &m_initialArticles );
1718
ini_sget( config, "apod", "articles", "%d", &m_numArticles );
1819
ini_sget( config, "apod", "refresh", "%d", &m_refresh );
1920
ini_sget( config, "apod", "failure", "%d", &m_failureRefresh );
2021

21-
const bool status = m_numArticles > 0;
22-
PrintStatus( status, "Initialization: configured for %i articles, refresh: %s", m_numArticles, FormatTime( m_refresh ) );
22+
const bool status = m_numArticles > 0 && m_initialArticles > 0;
23+
PrintStatus( status, "Initialization: configured for %i articles (%i initial), refresh: %s", m_numArticles, m_initialArticles, FormatTime( m_refresh ) );
2324
return status;
2425
}
2526

@@ -71,7 +72,7 @@ bool Apod::FetchImpl( bool first )
7172

7273
auto next = article->select_node( "//a[text()='<']" );
7374
if( !next ) return !m_articles.empty();
74-
if( first && ++num == m_numArticles ) return true;
75+
if( first && ++num == m_initialArticles ) return true;
7576

7677
url = m_baseUrl + next.node().attribute( "href" ).as_string();
7778
article = FetchDom( FetchPage( url.c_str() ) );

src/Handler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ bool Handler::Initialize( ini_t* config )
4242
m_feedUrlShort = "/apod";
4343
m_feedUrl = std::string( ini_get( config, "server", "url" ) ) + m_feedUrlShort;
4444

45+
ini_sget( config, "global", "initial", "%d", &m_initialArticles );
4546
ini_sget( config, "global", "articles", "%d", &m_numArticles );
4647
ini_sget( config, "global", "refresh", "%d", &m_refresh );
4748
ini_sget( config, "global", "failure", "%d", &m_failureRefresh );

src/Handler.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class Handler
6363

6464
std::string m_icon;
6565

66+
int m_initialArticles;
6667
int m_numArticles;
6768
int m_refresh;
6869
int m_failureRefresh;

0 commit comments

Comments
 (0)