From 33fb755e13f303c1530b1f2f078ea12732970039 Mon Sep 17 00:00:00 2001 From: Wang Zhiyong Date: Fri, 22 Mar 2024 06:16:39 +0000 Subject: [PATCH] update --- osgraph/api.cpp | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/osgraph/api.cpp b/osgraph/api.cpp index b8eea72efe..2be04b3b52 100644 --- a/osgraph/api.cpp +++ b/osgraph/api.cpp @@ -1,3 +1,4 @@ +#include #include "tools/lgraph_log.h" #include "core/data_type.h" namespace lgraph { @@ -377,11 +378,14 @@ std::string topn_developer(lgraph_api::GraphDB &db, const std::string& request) } } -std::unordered_set get_repos_by_developer(lgraph_api::GraphDB &db, int64_t developer_vid) { +std::set get_repos_by_developer(lgraph_api::GraphDB &db, int64_t developer_vid) { auto txn = db.CreateReadTxn(); auto vit = txn.GetVertexIterator(developer_vid); bool has_bot = false; auto developer_name = vit.GetField("name").AsString(); + if (boost::algorithm::ends_with(developer_name, "[bot]")) { + return {}; + } auto pos = developer_name.find("bot"); if (pos != std::string::npos) { has_bot = true; @@ -402,7 +406,7 @@ std::unordered_set get_repos_by_developer(lgraph_api::GraphDB &db, int6 int16_t open_issue_id = txn.GetEdgeLabelId("open_issue"); int16_t comment_issue_id = txn.GetEdgeLabelId("comment_issue"); - std::unordered_set repos; + std::set repos; /*{ int count = 0; lgraph_api::EdgeUid euid; @@ -527,7 +531,7 @@ std::unordered_set get_repos_by_developer(lgraph_api::GraphDB &db, int6 return repos; } -std::unordered_set get_developers_by_repo(lgraph_api::GraphDB &db, int64_t repo_vid) { +std::set get_developers_by_repo(lgraph_api::GraphDB &db, int64_t repo_vid) { auto txn = db.CreateReadTxn(); auto vit = txn.GetVertexIterator(repo_vid); @@ -542,7 +546,7 @@ std::unordered_set get_developers_by_repo(lgraph_api::GraphDB &db, int6 int16_t review_pr_id = txn.GetEdgeLabelId("review_pr"); int16_t comment_pr_id = txn.GetEdgeLabelId("comment_pr"); - std::unordered_set developers; + std::set developers; /*{ lgraph_api::EdgeUid euid; euid.lid = push_id; @@ -636,16 +640,20 @@ std::unordered_set get_developers_by_repo(lgraph_api::GraphDB &db, int6 return developers; } +struct common_developer { + std::string name; + std::vector developers; +}; + std::string get_repo_by_repo(lgraph_api::GraphDB &db, const std::string& request) { try { nlohmann::json input = nlohmann::json::parse(request); int64_t repo_id = input["repo_vid"].get(); - std::unordered_map> res; + std::unordered_map> res; auto txn = db.CreateReadTxn(); auto repo_iter = txn.GetVertexByUniqueIndex("github_repo", "id", FieldData::Int32(repo_id)); auto repo_vid = repo_iter.GetId(); txn.Abort(); - LOG_INFO() << "get_developers_by_repo begin"; auto developers = get_developers_by_repo(db, repo_vid); LOG_INFO() << FMA_FMT("get_developers_by_repo end, developers size {}", developers.size()); res[repo_vid] = developers; @@ -655,9 +663,25 @@ std::string get_repo_by_repo(lgraph_api::GraphDB &db, const std::string& request res[repo].insert(developer); } } + std::vector ret; + for (const auto& pair : res) { + common_developer deve; + deve.name = FMA_FMT("{}_{}",repo_vid, pair.first); + + std::set_intersection(developers.begin(), developers.end(), + pair.second.begin(), pair.second.end(), + std::back_inserter(deve.developers)); + ret.emplace_back(std::move(deve)); + } + std::sort(ret.begin(), ret.end(), [](const common_developer& a, const common_developer& b){ + return a.developers.size() > b.developers.size(); + }); + ret.resize(10); nlohmann::json output; output["ok"] = true; - output["response"] = res; + for (auto& item : ret) { + output["response"][item.name] = item.developers; + } return output.dump(); } catch (const std::exception& e) { auto err = e.what();