mirror of
https://github.com/clangen/musikcube.git
synced 2025-02-06 03:39:50 +00:00
Fixed out of control memory / CPU usage caused by unnecessary track
parsing.
This commit is contained in:
parent
139c669790
commit
ed313ecce0
@ -228,7 +228,7 @@ void CategoryTrackListQuery::DeserializeResult(const std::string& data) {
|
||||
this->SetStatus(IQuery::Failed);
|
||||
nlohmann::json result = nlohmann::json::parse(data)["result"];
|
||||
this->result = std::make_shared<TrackList>(this->library);
|
||||
TrackListFromJson(result["trackList"], *this->result, this->library);
|
||||
TrackListFromJson(result["trackList"], *this->result, this->library, true);
|
||||
JsonArrayToSet<std::set<size_t>, size_t>(result["headers"], *this->headers);
|
||||
this->SetStatus(IQuery::Finished);
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ void SearchTrackListQuery::DeserializeResult(const std::string& data) {
|
||||
this->SetStatus(IQuery::Failed);
|
||||
nlohmann::json result = nlohmann::json::parse(data)["result"];
|
||||
this->result = std::make_shared<TrackList>(this->library);
|
||||
TrackListFromJson(result["trackList"], *this->result, this->library);
|
||||
TrackListFromJson(result["trackList"], *this->result, this->library, true);
|
||||
JsonArrayToSet<std::set<size_t>, size_t>(result["headers"], *this->headers);
|
||||
this->SetStatus(IQuery::Finished);
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ void TrackMetadataQuery::DeserializeResult(const std::string& data) {
|
||||
this->SetStatus(IQuery::Failed);
|
||||
auto input = nlohmann::json::parse(data);
|
||||
auto parsedResult = std::make_shared<LibraryTrack>(-1LL, this->library);
|
||||
TrackFromJson(input["result"], parsedResult);
|
||||
TrackFromJson(input["result"], parsedResult, false);
|
||||
this->result = parsedResult;
|
||||
this->SetStatus(IQuery::Finished);
|
||||
}
|
||||
|
@ -38,6 +38,7 @@
|
||||
|
||||
using namespace musik::core;
|
||||
using namespace musik::core::library::query;
|
||||
using namespace musik::core::sdk;
|
||||
|
||||
namespace musik { namespace core { namespace library { namespace query {
|
||||
|
||||
@ -117,7 +118,7 @@ namespace musik { namespace core { namespace library { namespace query {
|
||||
#define COPY_TRACK_FIELD_TO_JSON(track, json, field) \
|
||||
json[field] = track->GetString(field);
|
||||
|
||||
nlohmann::json TrackToJson(const musik::core::TrackPtr input, bool onlyIds) {
|
||||
nlohmann::json TrackToJson(const TrackPtr input, bool onlyIds) {
|
||||
nlohmann::json output;
|
||||
|
||||
output["id"] = input->GetId();
|
||||
@ -198,22 +199,35 @@ namespace musik { namespace core { namespace library { namespace query {
|
||||
replayGain.trackPeak = replayGainJson.value("trackPeak", 1.0f);
|
||||
}
|
||||
|
||||
output->SetMetadataState(musik::core::sdk::MetadataState::Loaded);
|
||||
output->SetMetadataState(MetadataState::Loaded);
|
||||
}
|
||||
|
||||
nlohmann::json TrackListToJson(const musik::core::TrackList& input, bool onlyIds) {
|
||||
nlohmann::json TrackListToJson(const TrackList& input, bool onlyIds) {
|
||||
nlohmann::json output;
|
||||
for (size_t i = 0; i < input.Count(); i++) {
|
||||
output.push_back(TrackToJson(input.Get(i), onlyIds));
|
||||
if (onlyIds) {
|
||||
for (size_t i = 0; i < input.Count(); i++) {
|
||||
output.push_back(input.GetId(i));
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (size_t i = 0; i < input.Count(); i++) {
|
||||
output.push_back(TrackToJson(input.Get(i), onlyIds));
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
void TrackListFromJson(const nlohmann::json& input, musik::core::TrackList& output, musik::core::ILibraryPtr library) {
|
||||
void TrackListFromJson(const nlohmann::json& input, TrackList& output, ILibraryPtr library, bool onlyIds) {
|
||||
output.Clear();
|
||||
for (auto& trackJson : input) {
|
||||
TrackPtr track = std::make_shared<LibraryTrack>(-1LL, library);
|
||||
output.Add(trackJson["id"].get<int64_t>());
|
||||
if (onlyIds) {
|
||||
for (auto& trackId : input) {
|
||||
output.Add(trackId.get<int64_t>());
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (auto& trackJson : input) {
|
||||
output.Add(trackJson["id"].get<int64_t>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,16 +74,17 @@ namespace musik { namespace core { namespace library { namespace query {
|
||||
void TrackFromJson(
|
||||
const nlohmann::json& input,
|
||||
musik::core::TrackPtr output,
|
||||
bool onlyIds = false);
|
||||
bool onlyIds);
|
||||
|
||||
nlohmann::json TrackListToJson(
|
||||
const musik::core::TrackList& input,
|
||||
bool onlyIds = false);
|
||||
bool onlyIds);
|
||||
|
||||
void TrackListFromJson(
|
||||
const nlohmann::json& input,
|
||||
musik::core::TrackList& output,
|
||||
musik::core::ILibraryPtr library);
|
||||
musik::core::ILibraryPtr library,
|
||||
bool onlyIds);
|
||||
|
||||
template <typename SetType, typename DataType>
|
||||
void JsonArrayToSet(const nlohmann::json& input, SetType& output) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user