Skip to content

Commit

Permalink
Update sync process
Browse files Browse the repository at this point in the history
  • Loading branch information
arkid15r committed Sep 13, 2024
1 parent 3224933 commit a479556
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 15 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ migrate:
migrations:
@CMD="poetry run python manage.py makemigrations" $(MAKE) exec-backend-command

owasp-aggregate-projects-data:
@CMD="poetry run python manage.py owasp_aggregate_projects_data" $(MAKE) exec-backend-command

owasp-scrape-site-data:
@CMD="poetry run python manage.py owasp_scrape_site_data" $(MAKE) exec-backend-command

owasp-update-projects:
@CMD="poetry run python manage.py owasp_update_projects" $(MAKE) exec-backend-command

pre-commit:
@pre-commit run -a

Expand All @@ -63,8 +63,8 @@ sync: \
github-sync-owasp-organization \
owasp-scrape-site-data \
github-sync-related-repositories \
github_summarize_issues \
owasp-update-projects
github-summarize-issues \
owasp-aggregate-projects-data

test:
@docker build -f backend/Dockerfile.test backend -t nest-backend-test 2>/dev/null
Expand Down
4 changes: 2 additions & 2 deletions backend/apps/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class Meta:
abstract = True

@staticmethod
def bulk_save(model, objects):
def bulk_save(model, objects, fields=None):
"""Bulk save objects."""
model.objects.bulk_create((o for o in objects if not o.id), BATCH_SIZE)
model.objects.bulk_update(
(o for o in objects if o.id),
fields=[field.name for field in model._meta.fields if not field.primary_key], # noqa: SLF001
fields=fields or [field.name for field in model._meta.fields if not field.primary_key], # noqa: SLF001
batch_size=BATCH_SIZE,
)
objects.clear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def handle(self, *args, **options):
)
)

issue.summary = open_ai.set_input(f"{issue.title}\r\n{issue.body}").complete()
issue.summary = open_ai.set_input(f"{issue.title}\r\n{issue.body}").complete() or ""
issues.append(issue)

# Bulk save data.
Issue.bulk_save(issues)
Issue.bulk_save(issues, fields=("summary",))
5 changes: 2 additions & 3 deletions backend/apps/github/models/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,9 @@ def from_github(self, gh_issue, author=None, repository=None):
self.repository = repository

@staticmethod
def bulk_save(issues):
def bulk_save(issues, fields=None):
"""Bulk save issues."""
BulkSaveModel.bulk_save(Issue, issues)
issues.clear()
BulkSaveModel.bulk_save(Issue, issues, fields=fields)

@staticmethod
def update_data(gh_issue, author=None, repository=None, save=True):
Expand Down
1 change: 0 additions & 1 deletion backend/apps/github/models/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def from_github(self, gh_label):
def bulk_save(labels):
"""Bulk save labels."""
BulkSaveModel.bulk_save(Label, labels)
labels.clear()

@staticmethod
def update_data(gh_label, save=True):
Expand Down
1 change: 0 additions & 1 deletion backend/apps/github/models/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def from_github(self, gh_organization):
def bulk_save(organizations):
"""Bulk save organizations."""
BulkSaveModel.bulk_save(Organization, organizations)
organizations.clear()

@staticmethod
def update_data(gh_organization, save=True):
Expand Down
1 change: 0 additions & 1 deletion backend/apps/github/models/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ def from_github(self, gh_release, author=None, repository=None):
def bulk_save(releases):
"""Bulk save releases."""
BulkSaveModel.bulk_save(Release, releases)
releases.clear()

@staticmethod
def update_data(gh_release, author=None, repository=None, save=True):
Expand Down

0 comments on commit a479556

Please sign in to comment.