commit 829bc01209e57ceac2d2e2182266293b612d3c2a parent 2ef75f9bb2de3c3b93bd7a46067f892ae0fa47e8 Author: Dominik Schmidt <das1993@hotmail.com> Date: Sat, 1 Aug 2015 12:31:51 +0200 Check max_entries when update()ing Diffstat:
drss/rss.d | | | 24 | ++++++++++++++++++++++-- |
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/drss/rss.d b/drss/rss.d @@ -60,16 +60,36 @@ abstract class DRSS(T=Entry){ } } - final void update(){ - ubyte document[]=fetch(); + final bool update(ubyte document[]=null){ + if(document is null){ + document=fetch(); + } new_entries=0; parse(cast(string)document); + if(new_entries>max_entries){ + max_entries=new_entries+2; + } + if(entry_count>max_entries){ + removeOldEntries(); + } + return (new_entries>0); } @property size_t length(){ return entry_count; } + private void removeOldEntries(){ + auto r=entries[]; + auto i=max_entries; + while(i-->0 && !r.empty){ + r.popFront(); + } + if(!r.empty){ + entries.linearRemove(r); + } + } + public ubyte[] fetch(){ debug(RSS) writeln("Updateing"); auto h=HTTP();