diff --git a/src/source_package_publishing_history.cpp b/src/source_package_publishing_history.cpp index 29ea1e2..744cc7c 100644 --- a/src/source_package_publishing_history.cpp +++ b/src/source_package_publishing_history.cpp @@ -51,13 +51,12 @@ void source_package_publishing_history::parse_json(const std::string& json_data) } } -std::vector source_package_publishing_history::getBuilds() const { - std::vector builds; - if (self_link.empty()) { return builds; } +std::generator source_package_publishing_history::getBuilds() const { + if (self_link.empty()) { co_return; } std::map params = {{"ws.op", "getBuilds"}}; auto response = lp->api_get(self_link, params); - if (!response.has_value()) { return builds; } + if (!response.has_value()) { co_return; } try { auto data = nlohmann::json::parse(response.value()); @@ -66,14 +65,12 @@ std::vector source_package_publishing_history::getBuilds() const { auto b_opt = build::parse(entry.dump()); if(!b_opt.has_value()) continue; b_opt->set_lp(lp); - builds.push_back(b_opt.value()); + co_yield b_opt.value(); } } } catch (const std::exception& e) { std::cerr << "Error parsing builds: " << e.what() << std::endl; } - - return builds; } void source_package_publishing_history::set_lp(launchpad* lp_ptr) { diff --git a/src/source_package_publishing_history.h b/src/source_package_publishing_history.h index b4dac76..6093496 100644 --- a/src/source_package_publishing_history.h +++ b/src/source_package_publishing_history.h @@ -18,7 +18,7 @@ #include #include -#include +#include #include "build.h" class launchpad; @@ -40,7 +40,7 @@ public: static std::optional parse(const std::string& json_data); void parse_json(const std::string& json_data); - std::vector getBuilds() const; + std::generator getBuilds() const; std::string self_link; std::string source_package_name;