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

Code before:
                          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()));
  CServiceBroker::GetAppMessenger()->SendMsg(TMSG_EXECUTE_BUILT_IN, -1, -1, nullptr, cmd);

  return ACK;
}

bool CAudioLibrary::CheckForAdditionalProperties(const CVariant &properties, const std::set<std::string> &checkProperties, std::set<std::string> &foundProperties)
{
  if (!properties.isArray() || properties.empty())
    return false;

  std::set<std::string> checkingProperties = checkProperties;
  for (CVariant::const_iterator_array itr = properties.begin_array();
       itr != properties.end_array() && !checkingProperties.empty(); ++itr)
  {
    if (!itr->isString())
      continue;

    std::string property = itr->asString();
    if (checkingProperties.find(property) != checkingProperties.end())
    {
      checkingProperties.erase(property);
      foundProperties.insert(property);
    }
  }


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

Code after:
  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({})",
                                              StringUtils::Paramify(albumIdVariant.asString()));
  CServiceBroker::GetAppMessenger()->SendMsg(TMSG_EXECUTE_BUILT_IN, -1, -1, nullptr, cmd);

  return ACK;
}

bool CAudioLibrary::CheckForAdditionalProperties(const CVariant &properties, const std::set<std::string> &checkProperties, std::set<std::string> &foundProperties)
{
  if (!properties.isArray() || properties.empty())
    return false;

  std::set<std::string> checkingProperties = checkProperties;
  for (CVariant::const_iterator_array itr = properties.begin_array();
       itr != properties.end_array() && !checkingProperties.empty(); ++itr)
  {
    if (!itr->isString())
      continue;

    std::string property = itr->asString();
    if (checkingProperties.contains(property))
    {
      checkingProperties.erase(property);
      foundProperties.insert(property);
    }
  }