| @@ -1,177 +0,0 @@ | |||
| DROP FOREIGN TABLE public.pull_request_es; | |||
| CREATE FOREIGN TABLE public.pull_request_es | |||
| ( | |||
| id bigint NOT NULL, | |||
| type integer, | |||
| status integer, | |||
| conflicted_files json, | |||
| commits_ahead integer, | |||
| commits_behind integer, | |||
| issue_id bigint, | |||
| index bigint, | |||
| head_repo_id bigint, | |||
| base_repo_id bigint, | |||
| head_branch character varying(255), | |||
| base_branch character varying(255), | |||
| merge_base character varying(40), | |||
| has_merged boolean, | |||
| merged_commit_id character varying(40), | |||
| merger_id bigint, | |||
| merged_unix bigint, | |||
| is_transformed boolean NOT NULL DEFAULT false, | |||
| amount integer NOT NULL DEFAULT 0 | |||
| )SERVER multicorn_es | |||
| OPTIONS | |||
| ( | |||
| host '192.168.207.94', | |||
| port '9200', | |||
| index 'pr-es-index', | |||
| rowid_column 'id', | |||
| default_sort '_id' | |||
| ) | |||
| ; | |||
| delete from public.pull_request_es; | |||
| INSERT INTO public.pull_request_es( | |||
| id, | |||
| type, | |||
| status, | |||
| conflicted_files, | |||
| commits_ahead, | |||
| commits_behind, | |||
| issue_id, | |||
| index, | |||
| head_repo_id, | |||
| base_repo_id, | |||
| head_branch, | |||
| base_branch, | |||
| merge_base, | |||
| has_merged, | |||
| merged_commit_id, | |||
| merger_id, | |||
| merged_unix, | |||
| is_transformed, | |||
| amount) | |||
| SELECT | |||
| b.id, | |||
| b.type, | |||
| b.status, | |||
| b.conflicted_files, | |||
| b.commits_ahead, | |||
| b.commits_behind, | |||
| b.issue_id, | |||
| b.index, | |||
| b.head_repo_id, | |||
| b.base_repo_id, | |||
| b.head_branch, | |||
| b.base_branch, | |||
| b.merge_base, | |||
| b.has_merged, | |||
| b.merged_commit_id, | |||
| b.merger_id, | |||
| b.merged_unix, | |||
| b.is_transformed, | |||
| b.amount | |||
| FROM public.pull_request b,public.repository c where b.base_repo_id=c.id and c.is_private=false; | |||
| CREATE OR REPLACE FUNCTION public.insert_pull_request_data() RETURNS trigger AS | |||
| $def$ | |||
| DECLARE | |||
| privateValue boolean=false; | |||
| BEGIN | |||
| select into privateValue is_private from public.repository where id=NEW.base_repo_id; | |||
| if not privateValue then | |||
| INSERT INTO public.pull_request_es( | |||
| id, | |||
| type, | |||
| status, | |||
| conflicted_files, | |||
| commits_ahead, | |||
| commits_behind, | |||
| issue_id, | |||
| index, | |||
| head_repo_id, | |||
| base_repo_id, | |||
| head_branch, | |||
| base_branch, | |||
| merge_base, | |||
| has_merged, | |||
| merged_commit_id, | |||
| merger_id, | |||
| merged_unix, | |||
| is_transformed, | |||
| amount) | |||
| VALUES ( | |||
| NEW.id, | |||
| NEW.type, | |||
| NEW.status, | |||
| NEW.conflicted_files, | |||
| NEW.commits_ahead, | |||
| NEW.commits_behind, | |||
| NEW.issue_id, | |||
| NEW.index, | |||
| NEW.head_repo_id, | |||
| NEW.base_repo_id, | |||
| NEW.head_branch, | |||
| NEW.base_branch, | |||
| NEW.merge_base, | |||
| NEW.has_merged, | |||
| NEW.merged_commit_id, | |||
| NEW.merger_id, | |||
| NEW.merged_unix, | |||
| NEW.is_transformed, | |||
| NEW.amount | |||
| ); | |||
| UPDATE public.issue_es SET pr_id=NEW.id where id=NEW.issue_id; | |||
| end if; | |||
| RETURN NEW; | |||
| END; | |||
| $def$ | |||
| LANGUAGE plpgsql; | |||
| DROP TRIGGER IF EXISTS es_insert_pull_request on public.pull_request; | |||
| CREATE TRIGGER es_insert_pull_request | |||
| AFTER INSERT ON public.pull_request | |||
| FOR EACH ROW EXECUTE PROCEDURE insert_pull_request_data(); | |||
| ALTER TABLE public.pull_request ENABLE ALWAYS TRIGGER es_insert_pull_request; | |||
| CREATE OR REPLACE FUNCTION public.update_pull_request() RETURNS trigger AS | |||
| $def$ | |||
| declare | |||
| BEGIN | |||
| UPDATE public.pull_request_es | |||
| SET has_merged=NEW.has_merged | |||
| where id=NEW.id; | |||
| return new; | |||
| END | |||
| $def$ | |||
| LANGUAGE plpgsql; | |||
| DROP TRIGGER IF EXISTS es_update_pull_request on public.pull_request; | |||
| CREATE TRIGGER es_update_pull_request | |||
| AFTER UPDATE ON public.pull_request | |||
| FOR EACH ROW EXECUTE PROCEDURE update_pull_request(); | |||
| ALTER TABLE public.pull_request ENABLE ALWAYS TRIGGER es_update_pull_request; | |||
| CREATE OR REPLACE FUNCTION public.delete_pull_request() RETURNS trigger AS | |||
| $def$ | |||
| declare | |||
| BEGIN | |||
| DELETE FROM public.pull_request_es where id=OLD.id; | |||
| return new; | |||
| END | |||
| $def$ | |||
| LANGUAGE plpgsql; | |||
| DROP TRIGGER IF EXISTS es_delete_pull_request on public.pull_request; | |||
| CREATE TRIGGER es_delete_pull_request | |||
| AFTER DELETE ON public.pull_request | |||
| FOR EACH ROW EXECUTE PROCEDURE delete_pull_request(); | |||
| ALTER TABLE public.pull_request ENABLE ALWAYS TRIGGER es_delete_pull_request; | |||
| @@ -44,6 +44,8 @@ CREATE FOREIGN TABLE public.repository_es ( | |||
| download_cnt bigint DEFAULT 0 NOT NULL, | |||
| num_commit bigint DEFAULT 0 NOT NULL, | |||
| git_clone_cnt bigint DEFAULT 0 NOT NULL, | |||
| creator_id bigint NOT NULL DEFAULT 0, | |||
| repo_type integer NOT NULL DEFAULT 0, | |||
| lang character varying(2048), | |||
| alias character varying(255), | |||
| lower_alias character varying(255) | |||
| @@ -99,6 +101,8 @@ delete from public.repository_es; | |||
| clone_cnt, | |||
| num_commit, | |||
| git_clone_cnt, | |||
| creator_id, | |||
| repo_type, | |||
| lang, | |||
| alias, | |||
| lower_alias | |||
| @@ -145,6 +149,8 @@ delete from public.repository_es; | |||
| clone_cnt, | |||
| num_commit, | |||
| git_clone_cnt, | |||
| creator_id, | |||
| repo_type, | |||
| (select array_to_string(array_agg(language order by percentage desc),',') from public.language_stat a where a.repo_id=b.id), | |||
| alias, | |||
| lower_alias | |||
| @@ -196,6 +202,8 @@ $def$ | |||
| clone_cnt, | |||
| num_commit, | |||
| git_clone_cnt, | |||
| creator_id, | |||
| repo_type, | |||
| alias, | |||
| lower_alias) VALUES | |||
| (NEW.id, | |||
| @@ -239,6 +247,8 @@ $def$ | |||
| NEW.clone_cnt, | |||
| NEW.num_commit, | |||
| NEW.git_clone_cnt, | |||
| NEW.creator_id, | |||
| NEW.repo_type, | |||
| NEW.alias, | |||
| NEW.lower_alias); | |||
| end if; | |||
| @@ -303,6 +313,8 @@ $def$ | |||
| clone_cnt, | |||
| num_commit, | |||
| git_clone_cnt, | |||
| creator_id, | |||
| repo_type, | |||
| lang, | |||
| alias, | |||
| lower_alias) | |||
| @@ -348,6 +360,8 @@ $def$ | |||
| clone_cnt, | |||
| num_commit, | |||
| git_clone_cnt, | |||
| creator_id, | |||
| repo_type, | |||
| (select array_to_string(array_agg(language order by percentage desc),',') from public.language_stat a where a.repo_id=b.id), | |||
| alias, | |||
| lower_alias | |||
| @@ -429,54 +443,11 @@ $def$ | |||
| (select id from public.pull_request d where d.issue_id=b.id) | |||
| FROM public.issue b where b.repo_id=NEW.id; | |||
| INSERT INTO public.pull_request_es( | |||
| id, | |||
| type, | |||
| status, | |||
| conflicted_files, | |||
| commits_ahead, | |||
| commits_behind, | |||
| issue_id, | |||
| index, | |||
| head_repo_id, | |||
| base_repo_id, | |||
| head_branch, | |||
| base_branch, | |||
| merge_base, | |||
| has_merged, | |||
| merged_commit_id, | |||
| merger_id, | |||
| merged_unix, | |||
| is_transformed, | |||
| amount) | |||
| SELECT | |||
| b.id, | |||
| b.type, | |||
| b.status, | |||
| b.conflicted_files, | |||
| b.commits_ahead, | |||
| b.commits_behind, | |||
| b.issue_id, | |||
| b.index, | |||
| b.head_repo_id, | |||
| b.base_repo_id, | |||
| b.head_branch, | |||
| b.base_branch, | |||
| b.merge_base, | |||
| b.has_merged, | |||
| b.merged_commit_id, | |||
| b.merger_id, | |||
| b.merged_unix, | |||
| b.is_transformed, | |||
| b.amount | |||
| FROM public.pull_request b where b.base_repo_id=NEW.id; | |||
| end if; | |||
| if not OLD.is_private and NEW.is_private then | |||
| delete from public.issue_es where repo_id=NEW.id; | |||
| delete from public.dataset_es where repo_id=NEW.id; | |||
| delete from public.pull_request_es where base_repo_id=NEW.id; | |||
| delete from public.repository_es where id=NEW.id; | |||
| end if; | |||
| @@ -516,7 +487,6 @@ $def$ | |||
| BEGIN | |||
| delete from public.issue_es where repo_id=OLD.id; | |||
| delete from public.dataset_es where repo_id=OLD.id; | |||
| delete from public.pull_request_es where base_repo_id=OLD.id; | |||
| DELETE FROM public.repository_es where id=OLD.id; | |||
| return new; | |||
| END | |||
| @@ -533,14 +503,11 @@ ALTER TABLE public.repository ENABLE ALWAYS TRIGGER es_delete_repository; | |||
| CREATE OR REPLACE FUNCTION public.udpate_repository_lang() RETURNS trigger AS | |||
| $def$ | |||
| BEGIN | |||
| if (TG_OP = 'DELETE') then | |||
| update public.repository_es SET lang=(select array_to_string(array_agg(language order by percentage desc),',') from public.language_stat where repo_id=OLD.repo_id) where id=OLD.repo_id; | |||
| elsif (TG_OP = 'UPDATE') then | |||
| if (TG_OP = 'UPDATE') then | |||
| update public.repository_es SET lang=(select array_to_string(array_agg(language order by percentage desc),',') from public.language_stat where repo_id=NEW.repo_id) where id=NEW.repo_id; | |||
| elsif (TG_OP = 'INSERT') then | |||
| update public.repository_es SET lang=(select array_to_string(array_agg(language order by percentage desc),',') from public.language_stat where repo_id=NEW.repo_id) where id=NEW.repo_id; | |||
| end if; | |||
| return null; | |||
| END; | |||
| $def$ | |||
| @@ -577,7 +577,12 @@ function displayRepoResult(page,jsonResult,onlyReturnNum,keyword){ | |||
| html +=" <i class=\"icon fa-eye\">" +recordMap["num_watches"] + "</i> <i class=\"ri-star-line\"></i>" + recordMap["num_stars"] + " <i class=\"ri-git-branch-line am-ml-10\"></i>" + recordMap["num_forks"] +" "; | |||
| html +=" 最后更新于 " + recordMap["updated_html"]; | |||
| if(!isEmpty(recordMap["lang"])){ | |||
| html +=" <span class=\"text grey am-ml-10\"><i class=\"color-icon\" style=\"background-color: #3572A5\"></i>" + recordMap["lang"] + "</span>"; | |||
| var lang = recordMap["lang"] | |||
| var tmpLang = recordMap["lang"].split(","); | |||
| if(tmpLang.length>0){ | |||
| lang = tmpLang[0] | |||
| } | |||
| html +=" <span class=\"text grey am-ml-10\"><i class=\"color-icon\" style=\"background-color: #3572A5\"></i>" + lang + "</span>"; | |||
| } | |||
| html +=" </p>"; | |||
| html +=" </div>"; | |||