From e9ca72237fdec698e025264a3e526350ca08b329 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 19 Dec 2007 02:44:21 +0000 Subject: [PATCH] if tr_torrentStat() is called again in the same second for a torrent, return the cached value. --- libtransmission/internal.h | 1 + libtransmission/torrent.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/libtransmission/internal.h b/libtransmission/internal.h index 8ce58008f..9dc800f95 100644 --- a/libtransmission/internal.h +++ b/libtransmission/internal.h @@ -162,6 +162,7 @@ struct tr_torrent tr_recheck_state recheckState; + time_t lastStatTime; tr_stat stats[2]; tr_torrent * next; diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 08579a289..171076c39 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -713,6 +713,13 @@ tr_torrentStat( tr_torrent * tor ) { tr_stat * s; 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 );