-
Notifications
You must be signed in to change notification settings - Fork 851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize repo insertion and add repo src id #2929
Changes from all commits
431f58e
8214dc5
9ad160c
db7e9ef
7c6ea11
652d7f3
3d89a4f
02d1a17
35505e6
f7baea0
1966ad6
cfed800
18a84d1
aebe6ab
d39cca5
449917f
c7774bc
08a92a1
6940a26
8786f31
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
from flask import request, jsonify, redirect, url_for, flash, current_app | ||
Check warning on line 1 in augur/api/view/api.py
|
||
import re | ||
from flask_login import current_user, login_required | ||
from augur.application.db.models import Repo, RepoGroup, UserGroup, UserRepo | ||
from augur.tasks.frontend import add_org_repo_list, parse_org_and_repo_name, parse_org_name | ||
from augur.tasks.frontend import add_github_orgs_and_repos, parse_org_and_repo_name, parse_org_name, add_gitlab_repos | ||
from .utils import * | ||
from ..server import app | ||
from augur.application.db.session import DatabaseSession | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [pylint] reported by reviewdog 🐶 |
||
|
@@ -14,33 +14,21 @@ | |
return redirect(url_for('static', filename="cache")) | ||
return redirect(url_for('static', filename="cache/" + toCacheFilename(file, False))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [pylint] reported by reviewdog 🐶 |
||
|
||
|
||
def add_existing_repo_to_group(session, user_id, group_name, repo_id): | ||
|
||
logger.info("Adding existing repo to group") | ||
|
||
group_id = UserGroup.convert_group_name_to_id(session, user_id, group_name) | ||
if group_id is None: | ||
return False | ||
|
||
result = UserRepo.insert(session, repo_id, group_id) | ||
if not result: | ||
return False | ||
|
||
def add_existing_org_to_group(session, user_id, group_name, rg_id): | ||
|
||
logger.info("Adding existing org to group") | ||
Check warning on line 20 in augur/api/view/api.py
|
||
|
||
group_id = UserGroup.convert_group_name_to_id(session, user_id, group_name) | ||
if group_id is None: | ||
return False | ||
|
||
repos = session.query(Repo).filter(Repo.repo_group_id == rg_id).all() | ||
logger.info("Length of repos in org: " + str(len(repos))) | ||
Check warning on line 27 in augur/api/view/api.py
|
||
for repo in repos: | ||
result = UserRepo.insert(session, repo.repo_id, group_id) | ||
if not result: | ||
logger.info("Failed to add repo to group") | ||
Check warning on line 31 in augur/api/view/api.py
|
||
|
||
|
||
|
||
|
@@ -48,6 +36,8 @@ | |
@login_required | ||
def av_add_user_repo(): | ||
|
||
print("Adding user repos") | ||
|
||
urls = request.form.get('urls') | ||
group = request.form.get("group_name") | ||
|
||
|
@@ -68,58 +58,51 @@ | |
|
||
invalid_urls = [] | ||
|
||
with DatabaseSession(logger, current_app.engine) as session: | ||
for url in urls: | ||
|
||
# matches https://github.com/{org}/ or htts://github.com/{org} | ||
if (org_name := Repo.parse_github_org_url(url)): | ||
rg_obj = RepoGroup.get_by_name(session, org_name) | ||
if rg_obj: | ||
# add the orgs repos to the group | ||
add_existing_org_to_group(session, current_user.user_id, group, rg_obj.repo_group_id) | ||
|
||
# matches https://github.com/{org}/{repo}/ or htts://github.com/{org}/{repo} | ||
elif Repo.parse_github_repo_url(url)[0]: | ||
org_name, repo_name = Repo.parse_github_repo_url(url) | ||
repo_git = f"https://github.com/{org_name}/{repo_name}" | ||
repo_obj = Repo.get_by_repo_git(session, repo_git) | ||
if repo_obj: | ||
add_existing_repo_to_group(session, current_user.user_id, group, repo_obj.repo_id) | ||
|
||
# matches /{org}/{repo}/ or /{org}/{repo} or {org}/{repo}/ or {org}/{repo} | ||
elif (match := parse_org_and_repo_name(url)): | ||
org, repo = match.groups() | ||
repo_git = f"https://github.com/{org}/{repo}" | ||
repo_obj = Repo.get_by_repo_git(session, repo_git) | ||
if repo_obj: | ||
add_existing_repo_to_group(session, current_user.user_id, group, repo_obj.repo_id) | ||
orgs = [] | ||
repo_urls = [] | ||
gitlab_repo_urls = [] | ||
for url in urls: | ||
|
||
# matches https://github.com/{org}/ or htts://github.com/{org} | ||
if (org_name := Repo.parse_github_org_url(url)): | ||
orgs.append(org_name) | ||
|
||
# matches https://github.com/{org}/{repo}/ or htts://github.com/{org}/{repo} | ||
elif Repo.parse_github_repo_url(url)[0]: | ||
repo_urls.append(url) | ||
|
||
# matches /{org}/{repo}/ or /{org}/{repo} or {org}/{repo}/ or {org}/{repo} | ||
elif (match := parse_org_and_repo_name(url)): | ||
org, repo = match.groups() | ||
repo_git = f"https://github.com/{org}/{repo}" | ||
repo_urls.append(repo_git) | ||
|
||
# matches /{org}/ or /{org} or {org}/ or {org} | ||
elif (match := parse_org_name(url)): | ||
org_name = match.group(1) | ||
orgs.append(org_name) | ||
|
||
# matches https://gitlab.com/{org}/{repo}/ or http://gitlab.com/{org}/{repo} | ||
elif Repo.parse_gitlab_repo_url(url)[0]: | ||
|
||
org_name, repo_name = Repo.parse_gitlab_repo_url(url) | ||
repo_git = f"https://gitlab.com/{org_name}/{repo_name}" | ||
|
||
# matches /{org}/ or /{org} or {org}/ or {org} | ||
elif (match := parse_org_name(url)): | ||
org_name = match.group(1) | ||
rg_obj = RepoGroup.get_by_name(session, org_name) | ||
logger.info(rg_obj) | ||
if rg_obj: | ||
# add the orgs repos to the group | ||
add_existing_org_to_group(session, current_user.user_id, group, rg_obj.repo_group_id) | ||
|
||
# matches https://gitlab.com/{org}/{repo}/ or http://gitlab.com/{org}/{repo} | ||
elif Repo.parse_gitlab_repo_url(url)[0]: | ||
|
||
org_name, repo_name = Repo.parse_gitlab_repo_url(url) | ||
repo_git = f"https://gitlab.com/{org_name}/{repo_name}" | ||
|
||
# TODO: gitlab ensure the whole repo git is inserted so it can be found here | ||
repo_obj = Repo.get_by_repo_git(session, repo_git) | ||
if repo_obj: | ||
add_existing_repo_to_group(session, current_user.user_id, group, repo_obj.repo_id) | ||
|
||
else: | ||
invalid_urls.append(url) | ||
|
||
if urls: | ||
urls = [url.lower() for url in urls] | ||
add_org_repo_list.si(current_user.user_id, group, urls).apply_async() | ||
gitlab_repo_urls.append(repo_git) | ||
else: | ||
invalid_urls.append(url) | ||
|
||
|
||
|
||
if orgs or repo_urls: | ||
repo_urls = [url.lower() for url in repo_urls] | ||
orgs = [url.lower() for url in orgs] | ||
flash(f"Adding repos: {repo_urls}") | ||
flash(f"Adding orgs: {orgs}") | ||
add_github_orgs_and_repos.si(current_user.user_id, group, orgs, repo_urls).apply_async() | ||
|
||
if gitlab_repo_urls: | ||
add_gitlab_repos(current_user.user_id, group, gitlab_repo_urls) | ||
|
||
flash("Adding repos and orgs in the background") | ||
|
||
|
@@ -226,5 +209,5 @@ | |
""" | ||
@app.route('/requests/report/wait/<id>') | ||
def wait_for_report_request(id): | ||
requestReports(id) | ||
Check warning on line 212 in augur/api/view/api.py
|
||
return jsonify(report_requests[id]) | ||
Check warning on line 213 in augur/api/view/api.py
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"""Add repo src id | ||
|
||
Revision ID: 30 | ||
Revises: 29 | ||
Create Date: 2024-08-30 | ||
|
||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '30' | ||
down_revision = '29' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
op.add_column('repo', sa.Column('repo_src_id', sa.BigInteger(), nullable=True), schema='augur_data') | ||
op.create_unique_constraint('repo_src_id_unique', 'repo', ['repo_src_id'], schema='augur_data') | ||
|
||
|
||
def downgrade(): | ||
op.drop_constraint('repo_src_id_unique', 'repo', schema='augur_data', type_='unique') | ||
op.drop_column('repo', 'repo_src_id', schema='augur_data') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[pylint] reported by reviewdog 🐶
W0611: Unused RepoGroup imported from augur.application.db.models (unused-import)