berloga777 / lastfm-sharp

Automatically exported from code.google.com/p/lastfm-sharp
GNU General Public License v3.0
0 stars 0 forks source link

A whole lot of unnecessary server queries #2

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Maybe not technically a bug, but some unexpected behavior:
I'm trying to do a relatively straightforward operation (or something that
should be anyway): given a MusicBrains ID, I want to retrieve the number of
plays a user (in this case: me) has for that artist.

The only way I currently see for doing this, is looping through all the
artists in someone's library. As far as I can tell this is a limitation of
the Last.fm API.

Thus, I end up with something like this:

int playCount = 0;
for (int page = 1; page <= pageCount; page++)
{
    LibraryArtist[] artists = artistsQuery.GetPage(page);
    foreach (LibraryArtist a in artists)
    {
        if (a.Artist.GetMBID() == artist.MusicBrainsID)
        {
            playCount = a.Playcount;
            page = pageCount + 1;
            break;
        }
    }
}

This however turned out to be terribly slow. Apparently lastfm-sharp is
doing individual getInfo queries on all the artists I'm looping through,
when it shouldn't need to. The original page of library data has all the
info I need in this case: playcount and MBID.

I haven't looked at the source code yet, but it seems to me that the Artist
object could be prefilled with the data supplied by the library.getArtists
response and that an extra query would only be done if I request
information that is not already included.

(Using version 0.1.0.7 on Microsoft .NET)

Original issue reported on code.google.com by thora...@tiwaz.org on 30 Dec 2008 at 12:50

GoogleCodeExporter commented 8 years ago
It's a design limitations. Code is tidier this way. I'll see into pre-filling 
the
objects anyway.

Original comment by amr.hassan on 15 Jan 2009 at 9:48