aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-01-18 15:40:28 +0100
committerMax Kellermann <max@duempel.org>2009-01-18 15:40:28 +0100
commit91fb2a29deaafcc0ae9c710aec3c5cf54ce60d91 (patch)
tree03c1630db5f1f991dbe7d1cca7dd57793d61f0b3 /src
parent0d449d8df745c5c527f637f42e33156b92ac174d (diff)
downloadmpd-91fb2a29deaafcc0ae9c710aec3c5cf54ce60d91.tar.gz
mpd-91fb2a29deaafcc0ae9c710aec3c5cf54ce60d91.tar.xz
mpd-91fb2a29deaafcc0ae9c710aec3c5cf54ce60d91.zip
stats: added num_artists, num_albums
Don't recalculate the number of artists and albums each time a client requests statistics. Calculate that once in stats_update().
Diffstat (limited to 'src')
-rw-r--r--src/stats.c18
-rw-r--r--src/stats.h6
2 files changed, 16 insertions, 8 deletions
diff --git a/src/stats.c b/src/stats.c
index ce7ecb2d7..119b12456 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -33,12 +33,6 @@ void stats_global_init(void)
stats.start_time = time(NULL);
}
-void stats_update(void)
-{
- stats.song_count = countSongsIn(NULL);
- stats.song_duration = sumSongTimesIn(NULL);
-}
-
struct visit_data {
enum tag_type type;
struct strset *set;
@@ -78,6 +72,14 @@ getNumberOfTagItems(enum tag_type type)
return ret;
}
+void stats_update(void)
+{
+ stats.song_count = countSongsIn(NULL);
+ stats.song_duration = sumSongTimesIn(NULL);
+ stats.artist_count = getNumberOfTagItems(TAG_ITEM_ARTIST);
+ stats.album_count = getNumberOfTagItems(TAG_ITEM_ALBUM);
+}
+
int stats_print(struct client *client)
{
client_printf(client,
@@ -88,8 +90,8 @@ int stats_print(struct client *client)
"playtime: %li\n"
"db_playtime: %li\n"
"db_update: %li\n",
- getNumberOfTagItems(TAG_ITEM_ARTIST),
- getNumberOfTagItems(TAG_ITEM_ALBUM),
+ stats.artist_count,
+ stats.album_count,
stats.song_count,
time(NULL) - stats.start_time,
(long)(getPlayerTotalPlayTime() + 0.5),
diff --git a/src/stats.h b/src/stats.h
index 143ee0045..0c82cb16c 100644
--- a/src/stats.h
+++ b/src/stats.h
@@ -30,6 +30,12 @@ struct stats {
/** sum of all song durations in the music directory (in
seconds) */
unsigned long song_duration;
+
+ /** number of distinct artist names in the music directory */
+ unsigned artist_count;
+
+ /** number of distinct album names in the music directory */
+ unsigned album_count;
};
extern struct stats stats;