Repository: xbmc/xbmc
File: xbmc/interfaces/json-rpc/AudioLibrary.cpp (C++)

Code before:
      }
    }
  }

  return OK;
}

JSONRPC_STATUS CAudioLibrary::RefreshArtist(const std::string& method,
                                            ITransportLayer* transport,
                                            IClient* client,
                                            const CVariant& parameterObject,
                                            CVariant& result)
{
  CMusicDatabase musicdatabase;
  if (!musicdatabase.Open())
    return InternalError;

  // Checking if artistID is a valid one
  int artistID = (int)parameterObject["artistid"].asInteger();
  if (!musicdatabase.GetArtistExists(artistID))
    return InvalidParams;

  // Start rescraping additional information for the given artist
  const std::string cmd =
      StringUtils::Format("musiclibrary.refreshartist({})",
                          StringUtils::Paramify(parameterObject["artistid"].asString()));
  CServiceBroker::GetAppMessenger()->SendMsg(TMSG_EXECUTE_BUILT_IN, -1, -1, nullptr, cmd);

  return ACK;
}

JSONRPC_STATUS CAudioLibrary::RefreshAlbum(const std::string& method,
                                           ITransportLayer* transport,
                                           IClient* client,
                                           const CVariant& parameterObject,
                                           CVariant& result)
{
  CMusicDatabase musicdatabase;
  if (!musicdatabase.Open())
    return InternalError;

  // Check if albumID is a valid one
  CAlbum album;
  int albumID = (int)parameterObject["albumid"].asInteger();
  if (!musicdatabase.GetAlbum(albumID, album, false))
    return InvalidParams;

  // Start rescraping additional information for the given album
  const std::string cmd =
      StringUtils::Format("musiclibrary.refreshalbum({})",
                          StringUtils::Paramify(parameterObject["albumid"].asString()));

Review comment (performance):
For performance reasons I would introduce a variable for the artistid variant and use it at the two place where you need it in this method.

`const CVariant artistIdVariant{parameterObject["artistid"]};`

Code after:
        musicdatabase.GetArtistsByAlbum(item->GetMusicInfoTag()->GetAlbumId(), item.get());
      }
    }
  }

  return OK;
}

JSONRPC_STATUS CAudioLibrary::RefreshArtist(const std::string& method,
                                            ITransportLayer* transport,
                                            IClient* client,
                                            const CVariant& parameterObject,
                                            CVariant& result)
{
  CMusicDatabase musicdatabase;
  if (!musicdatabase.Open())
    return InternalError;

  // Checking if artistID is a valid one
  const CVariant artistIdVariant{parameterObject["artistid"]};
  const int artistID = static_cast<int>(artistIdVariant.asInteger());
  if (!musicdatabase.GetArtistExists(artistID))
    return InvalidParams;

  // Start rescraping additional information for the given artist
  const std::string cmd = StringUtils::Format("musiclibrary.refreshartist({})",
                                              StringUtils::Paramify(artistIdVariant.asString()));
  CServiceBroker::GetAppMessenger()->SendMsg(TMSG_EXECUTE_BUILT_IN, -1, -1, nullptr, cmd);

  return ACK;
}

JSONRPC_STATUS CAudioLibrary::RefreshAlbum(const std::string& method,
                                           ITransportLayer* transport,
                                           IClient* client,
                                           const CVariant& parameterObject,
                                           CVariant& result)
{
  CMusicDatabase musicdatabase;
  if (!musicdatabase.Open())
    return InternalError;

  // Check if albumID is a valid one
  CAlbum album;
  const CVariant albumIdVariant{parameterObject["albumid"]};
  const int albumID = static_cast<int>(albumIdVariant.asInteger());
  if (!musicdatabase.GetAlbum(albumID, album, false))
    return InvalidParams;

  // Start rescraping additional information for the given album
  const std::string cmd = StringUtils::Format("musiclibrary.refreshalbum({})",