Browse Source

提交代码。

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.22.3.2^2
zouap 4 years ago
parent
commit
8ab81f00f4
6 changed files with 366 additions and 147 deletions
  1. +14
    -14
      models/dbsql/dataset_foreigntable_for_es.sql
  2. +23
    -23
      models/dbsql/issue_foreigntable_for_es.sql
  3. +23
    -22
      models/dbsql/pr_foreigntable_for_es.sql
  4. +301
    -87
      models/dbsql/repo_foreigntable_for_es.sql
  5. +1
    -1
      models/dbsql/user_foreigntable_for_es.sql
  6. +4
    -0
      routers/repo/ai_model_manage.go

+ 14
- 14
models/dbsql/dataset_foreigntable_for_es.sql View File

@@ -40,20 +40,20 @@ DELETE FROM public.dataset_es;
created_unix,
updated_unix,file_name)
SELECT
id,
title,
status,
category,
description,
download_times,
license,
task,
release_id,
user_id,
repo_id,
created_unix,
updated_unix,(select array_to_string(array_agg(name order by created_unix desc),',') from public.attachment a where a.dataset_id=b.id)
FROM public.dataset b;
b.id,
b.title,
b.status,
b.category,
b.description,
b.download_times,
b.license,
b.task,
b.release_id,
b.user_id,
b.repo_id,
b.created_unix,
b.updated_unix,(select array_to_string(array_agg(name order by created_unix desc),',') from public.attachment a where a.dataset_id=b.id)
FROM public.dataset b,public.repository c where b.repo_id=c.id and c.is_private=false;

CREATE OR REPLACE FUNCTION public.insert_dataset_data() RETURNS trigger AS
$def$


+ 23
- 23
models/dbsql/issue_foreigntable_for_es.sql View File

@@ -35,7 +35,7 @@ OPTIONS
)
;

DELETE FROM public.issue_es;
delete from public.issue_es;
INSERT INTO public.issue_es(
id,
repo_id,
@@ -59,29 +59,29 @@ INSERT INTO public.issue_es(
amount,
is_transformed,comment)
SELECT
id,
repo_id,
index,
poster_id,
original_author,
original_author_id,
name,
content,
milestone_id,
priority,
is_closed,
is_pull,
num_comments,
ref,
deadline_unix,
created_unix,
updated_unix,
closed_unix,
is_locked,
amount,
is_transformed,
b.id,
b.repo_id,
b.index,
b.poster_id,
b.original_author,
b.original_author_id,
b.name,
b.content,
b.milestone_id,
b.priority,
b.is_closed,
b.is_pull,
b.num_comments,
b.ref,
b.deadline_unix,
b.created_unix,
b.updated_unix,
b.closed_unix,
b.is_locked,
b.amount,
b.is_transformed,
(select array_to_string(array_agg(content order by created_unix desc),',') from public.comment a where a.issue_id=b.id)
FROM public.issue b;
FROM public.issue b,public.repository c where b.repo_id=c.id and c.is_private=false;


CREATE OR REPLACE FUNCTION public.insert_issue_data() RETURNS trigger AS


+ 23
- 22
models/dbsql/pr_foreigntable_for_es.sql View File

@@ -53,27 +53,26 @@ delete from public.pull_request_es;
is_transformed,
amount)
SELECT
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
FROM public.pull_request;

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
@@ -81,7 +80,7 @@ $def$
DECLARE
privateValue boolean=false;
BEGIN
select into privateValue is_private from public.repository where id=NEW.repo_id;
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,
@@ -124,6 +123,8 @@ $def$
NEW.is_transformed,
NEW.amount
);
UPDATE public.issue_es SET pr_id=NEW.id where id=NEW.issue_id;
end if;
RETURN NEW;
END;


+ 301
- 87
models/dbsql/repo_foreigntable_for_es.sql View File

@@ -56,7 +56,97 @@ OPTIONS
)
;
delete from public.repository_es;
INSERT INTO public.repository_es (id,
INSERT INTO public.repository_es (id,
owner_id,
owner_name,
lower_name,
name,
description,
website,
original_service_type,
original_url,
default_branch,
num_watches,
num_stars,
num_forks,
num_issues,
num_closed_issues,
num_pulls,
num_closed_pulls,
num_milestones,
num_closed_milestones,
is_private,
is_empty,
is_archived,
is_mirror,
status,
is_fork,
fork_id,
is_template,
template_id,
size,
is_fsck_enabled,
close_issues_via_commit_in_any_branch,
topics,
avatar,
created_unix,
updated_unix,
contract_address,
block_chain_status,
balance,
clone_cnt,
num_commit,
git_clone_cnt,lang)
SELECT
id,
owner_id,
owner_name,
lower_name,
name,
description,
website,
original_service_type,
original_url,
default_branch,
num_watches,
num_stars,
num_forks,
num_issues,
num_closed_issues,
num_pulls,
num_closed_pulls,
num_milestones,
num_closed_milestones,
is_private,
is_empty,
is_archived,
is_mirror,
status,
is_fork,
fork_id,
is_template,
template_id,
size,
is_fsck_enabled,
close_issues_via_commit_in_any_branch,
topics,
avatar,
created_unix,
updated_unix,
contract_address,
block_chain_status,
balance,
clone_cnt,
num_commit,
git_clone_cnt,(select string_agg(language, ',') from public.language_stat a where a.repo_id=b.id)
FROM public.repository b where b.is_private=false;


CREATE OR REPLACE FUNCTION public.insert_repository_data() RETURNS trigger AS
$def$
BEGIN
if not NEW.is_private then
INSERT INTO public.repository_es (id,
owner_id,
owner_name,
lower_name,
@@ -96,9 +186,70 @@ INSERT INTO public.repository_es (id,
balance,
clone_cnt,
num_commit,
git_clone_cnt,lang)
SELECT
id,
git_clone_cnt) VALUES
(NEW.id,
NEW.owner_id,
NEW.owner_name,
NEW.lower_name,
NEW.name,
NEW.description,
NEW.website,
NEW.original_service_type,
NEW.original_url,
NEW.default_branch,
NEW.num_watches,
NEW.num_stars,
NEW.num_forks,
NEW.num_issues,
NEW.num_closed_issues,
NEW.num_pulls,
NEW.num_closed_pulls,
NEW.num_milestones,
NEW.num_closed_milestones,
NEW.is_private,
NEW.is_empty,
NEW.is_archived,
NEW.is_mirror,
NEW.status,
NEW.is_fork,
NEW.fork_id,
NEW.is_template,
NEW.template_id,
NEW.size,
NEW.is_fsck_enabled,
NEW.close_issues_via_commit_in_any_branch,
NEW.topics,
NEW.avatar,
NEW.created_unix,
NEW.updated_unix,
NEW.contract_address,
NEW.block_chain_status,
NEW.balance,
NEW.clone_cnt,
NEW.num_commit,
NEW.git_clone_cnt);
end if;
RETURN NEW;
END;
$def$
LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS es_insert_repository on public.repository;


CREATE TRIGGER es_insert_repository
AFTER INSERT ON public.repository
FOR EACH ROW EXECUTE PROCEDURE insert_repository_data();

ALTER TABLE public.repository ENABLE ALWAYS TRIGGER es_insert_repository;

CREATE OR REPLACE FUNCTION public.update_repository() RETURNS trigger AS
$def$
BEGIN
if OLD.is_private != NEW.is_private then
if OLD.is_private and not NEW.is_private then
--insert
INSERT INTO public.repository_es (id,
owner_id,
owner_name,
lower_name,
@@ -138,15 +289,9 @@ INSERT INTO public.repository_es (id,
balance,
clone_cnt,
num_commit,
git_clone_cnt,(select string_agg(language, ',') from public.language_stat a where a.repo_id=b.id)
FROM public.repository b where b.is_private=false;


CREATE OR REPLACE FUNCTION public.insert_repository_data() RETURNS trigger AS
$def$
BEGIN
if not NEW.is_private then
INSERT INTO public.repository_es (id,
git_clone_cnt,lang)
SELECT
id,
owner_id,
owner_name,
lower_name,
@@ -186,86 +331,152 @@ $def$
balance,
clone_cnt,
num_commit,
git_clone_cnt) VALUES
(NEW.id,
NEW.owner_id,
NEW.owner_name,
NEW.lower_name,
NEW.name,
NEW.description,
NEW.website,
NEW.original_service_type,
NEW.original_url,
NEW.default_branch,
NEW.num_watches,
NEW.num_stars,
NEW.num_forks,
NEW.num_issues,
NEW.num_closed_issues,
NEW.num_pulls,
NEW.num_closed_pulls,
NEW.num_milestones,
NEW.num_closed_milestones,
NEW.is_private,
NEW.is_empty,
NEW.is_archived,
NEW.is_mirror,
NEW.status,
NEW.is_fork,
NEW.fork_id,
NEW.is_template,
NEW.template_id,
NEW.size,
NEW.is_fsck_enabled,
NEW.close_issues_via_commit_in_any_branch,
NEW.topics,
NEW.avatar,
NEW.created_unix,
NEW.updated_unix,
NEW.contract_address,
NEW.block_chain_status,
NEW.balance,
NEW.clone_cnt,
NEW.num_commit,
NEW.git_clone_cnt);
end if;
RETURN NEW;
END;
$def$
LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS es_insert_repository on public.repository;


CREATE TRIGGER es_insert_repository
AFTER INSERT ON public.repository
FOR EACH ROW EXECUTE PROCEDURE insert_repository_data();

ALTER TABLE public.repository ENABLE ALWAYS TRIGGER es_insert_repository;
git_clone_cnt,(select string_agg(language, ',') from public.language_stat a where a.repo_id=b.id)
FROM public.repository b where b.id=NEW.id;
INSERT INTO public.dataset_es(
id,
title,
status,
category,
description,
download_times,
license, task,
release_id,
user_id,
repo_id,
created_unix,
updated_unix,file_name)
SELECT
b.id,
b.title,
b.status,
b.category,
b.description,
b.download_times,
b.license,
b.task,
b.release_id,
b.user_id,
b.repo_id,
b.created_unix,
b.updated_unix,(select array_to_string(array_agg(name order by created_unix desc),',') from public.attachment a where a.dataset_id=b.id)
FROM public.dataset b where b.repo_id=NEW.id;

CREATE OR REPLACE FUNCTION public.update_repository() RETURNS trigger AS
$def$
BEGIN
if OLD.is_private != NEW.is_private then
if OLD.is_private and not NEW.is_private then
--delete
INSERT INTO public.issue_es(
id,
repo_id,
index,
poster_id,
original_author,
original_author_id,
name,
content,
milestone_id,
priority,
is_closed,
is_pull,
num_comments,
ref,
deadline_unix,
created_unix,
updated_unix,
closed_unix,
is_locked,
amount,
is_transformed,comment,pr_id)
SELECT
b.id,
b.repo_id,
b.index,
b.poster_id,
b.original_author,
b.original_author_id,
b.name,
b.content,
b.milestone_id,
b.priority,
b.is_closed,
b.is_pull,
b.num_comments,
b.ref,
b.deadline_unix,
b.created_unix,
b.updated_unix,
b.closed_unix,
b.is_locked,
b.amount,
b.is_transformed,
(select array_to_string(array_agg(content order by created_unix desc),',') from public.comment a where a.issue_id=b.id),
(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;

end if;

update public.repository_es SET description=NEW.description,
name=NEW.name,
lower_name=NEW.lower_name,
owner_name=NEW.owner_name,
website=NEW.website,
updated_unix=NEW.updated_unix,
num_watches=NEW.num_watches,
num_stars=NEW.num_stars,
num_forks=NEW.num_forks,
topics=NEW.topics
where id=NEW.id;
return new;
if not NEW.is_private then
update public.repository_es SET description=NEW.description,
name=NEW.name,
lower_name=NEW.lower_name,
owner_name=NEW.owner_name,
website=NEW.website,
updated_unix=NEW.updated_unix,
num_watches=NEW.num_watches,
num_stars=NEW.num_stars,
num_forks=NEW.num_forks,
topics=NEW.topics
where id=NEW.id;
return new;
end if;
END
$def$
LANGUAGE plpgsql;
@@ -281,6 +492,9 @@ CREATE OR REPLACE FUNCTION public.delete_repository() RETURNS trigger AS
$def$
declare
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


+ 1
- 1
models/dbsql/user_foreigntable_for_es.sql View File

@@ -60,7 +60,7 @@ OPTIONS
default_sort '_id'
)
;
delete from public.user_es;
delete from public.user_es;
INSERT INTO public.user_es(
id,
lower_name,


+ 4
- 0
routers/repo/ai_model_manage.go View File

@@ -626,6 +626,7 @@ func QueryModelListForPredict(ctx *context.Context) {

func QueryModelFileForPredict(ctx *context.Context) {
id := ctx.Query("ID")
parentDir := ctx.Query("parentDir")
model, err := models.QueryModelById(id)
if err != nil {
log.Error("no such model!", err.Error())
@@ -633,6 +634,9 @@ func QueryModelFileForPredict(ctx *context.Context) {
return
}
prefix := model.Path[len(setting.Bucket)+1:]
if parentDir != "" {
prefix = prefix + parentDir
}
fileinfos, err := storage.GetAllObjectByBucketAndPrefix(setting.Bucket, prefix)
ctx.JSON(http.StatusOK, fileinfos)
}

Loading…
Cancel
Save