if tr_torrentStat() is called again in the same second for a torrent, return the cached value.
This commit is contained in:
parent
b498e720e6
commit
e9ca72237f
|
@ -162,6 +162,7 @@ struct tr_torrent
|
||||||
|
|
||||||
tr_recheck_state recheckState;
|
tr_recheck_state recheckState;
|
||||||
|
|
||||||
|
time_t lastStatTime;
|
||||||
tr_stat stats[2];
|
tr_stat stats[2];
|
||||||
|
|
||||||
tr_torrent * next;
|
tr_torrent * next;
|
||||||
|
|
|
@ -713,6 +713,13 @@ tr_torrentStat( tr_torrent * tor )
|
||||||
{
|
{
|
||||||
tr_stat * s;
|
tr_stat * s;
|
||||||
struct tr_tracker * tc;
|
struct tr_tracker * tc;
|
||||||
|
const time_t now = time( NULL );
|
||||||
|
|
||||||
|
/* generating these stats is expensive --
|
||||||
|
* update a maximum of once per second */
|
||||||
|
if( tor->lastStatTime == now )
|
||||||
|
return &tor->stats[tor->statCur];
|
||||||
|
tor->lastStatTime = now;
|
||||||
|
|
||||||
tr_torrentLock( tor );
|
tr_torrentLock( tor );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue