Lazy load distribution.current_series
This commit is contained in:
parent
f6c2b58e47
commit
5a47dd5c8d
@ -24,7 +24,26 @@ distribution::distribution()
|
||||
title(""),
|
||||
summary(""),
|
||||
domain_name(""),
|
||||
lp(nullptr) {}
|
||||
lp(nullptr),
|
||||
current_series([this]() -> std::optional<distro_series> {
|
||||
if (current_series_link.empty()) return std::nullopt;
|
||||
if (_current_series) return _current_series;
|
||||
|
||||
auto response = lp ? lp->api_get(current_series_link) : std::nullopt;
|
||||
if (!response) return std::nullopt;
|
||||
|
||||
auto data = nlohmann::json::parse(response.value());
|
||||
auto ds = distro_series::parse(data.dump());
|
||||
|
||||
if (ds) {
|
||||
ds->set_lp(lp);
|
||||
_current_series = ds;
|
||||
return ds;
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
})
|
||||
{}
|
||||
|
||||
distribution::~distribution() {}
|
||||
|
||||
@ -47,6 +66,7 @@ void distribution::parse_json(const std::string& json_data) {
|
||||
{"summary", [this](const nlohmann::json& val) { summary = val.get<std::string>(); }},
|
||||
{"domain_name", [this](const nlohmann::json& val) { domain_name = val.get<std::string>(); }},
|
||||
{"self_link", [this](const nlohmann::json& val) { self_link = val.get<std::string>(); }},
|
||||
{"current_series_link", [this](const nlohmann::json& val) { current_series_link = val.get<std::string>(); }},
|
||||
{"web_link", [this](const nlohmann::json& val) { web_link = val.get<std::string>(); }},
|
||||
{"translationgroup_link", [this](const nlohmann::json& val) { translationgroup_link = val.get<std::string>(); }}
|
||||
};
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <nlohmann/json.hpp>
|
||||
#include "launchpad.h"
|
||||
#include "distro_series.h"
|
||||
#include "lazy_optional.h"
|
||||
|
||||
#ifndef LAUNCHPAD_API
|
||||
#ifdef BUILDING_LAUNCHPAD
|
||||
@ -63,13 +64,16 @@ public:
|
||||
std::string archive_mirrors_collection_link;
|
||||
std::string archives_collection_link;
|
||||
std::string main_archive_link;
|
||||
std::string current_series_link;
|
||||
std::string series_collection_link;
|
||||
std::string valid_specifications_collection_link;
|
||||
std::string vulnerabilities_collection_link;
|
||||
std::string webhooks_collection_link;
|
||||
|
||||
lazy_optional<distro_series, std::function<std::optional<distro_series>()>> current_series;
|
||||
private:
|
||||
launchpad* lp;
|
||||
std::optional<distro_series> _current_series = std::nullopt;
|
||||
|
||||
// JSON parsing utility
|
||||
void parse_json(const std::string& json_data);
|
||||
|
Loading…
x
Reference in New Issue
Block a user