stats: use one db_walk() to obtain stats

Don't use dbUtils.h functions.  This reduces 4 full database walks to
just one.
This commit is contained in:
Max Kellermann
2009-01-18 15:40:50 +01:00
parent 91fb2a29de
commit 14ca99b224
3 changed files with 47 additions and 76 deletions

View File

@@ -50,16 +50,6 @@ typedef struct _SearchStats {
unsigned long playTime;
} SearchStats;
static int
countSongsInDirectory(struct directory *directory, void *data)
{
int *count = (int *)data;
*count += directory->songs.nr;
return 0;
}
static int
printDirectoryInDirectory(struct directory *directory, void *data)
{
@@ -237,43 +227,12 @@ directoryPrintSongInfo(struct song *song, void *data)
return 0;
}
static int
sumSongTime(struct song *song, void *data)
{
unsigned long *sum_time = (unsigned long *)data;
if (song->tag && song->tag->time >= 0)
*sum_time += song->tag->time;
return 0;
}
int printInfoForAllIn(struct client *client, const char *name)
{
return db_walk(name, directoryPrintSongInfo,
printDirectoryInDirectory, client);
}
int countSongsIn(const char *name)
{
int count = 0;
void *ptr = (void *)&count;
db_walk(name, NULL, countSongsInDirectory, ptr);
return count;
}
unsigned long sumSongTimesIn(const char *name)
{
unsigned long dbPlayTime = 0;
void *ptr = (void *)&dbPlayTime;
db_walk(name, sumSongTime, NULL, ptr);
return dbPlayTime;
}
static ListCommandItem *newListCommandItem(int tagType, int numConditionals,
LocateTagItem * conditionals)
{