Skip to content

Commit

Permalink
Use get_or_create when creating Resources
Browse files Browse the repository at this point in the history
Signed-off-by: Jono Yang <jyang@nexb.com>de
  • Loading branch information
JonoYang committed Jun 27, 2023
1 parent 8768c0d commit 00021b2
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions minecode/management/commands/process_scans.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def _update_package_checksums(package, scan_object):
return updated


def index_package_files(package, scan_data):
def index_package_files(package, scan_data, overwrite_fields=False):
"""
Index scan data for `package` Package.
Expand Down Expand Up @@ -216,7 +216,7 @@ def index_package_files(package, scan_data):

# TODO: Determine what extra_data to keep

r = Resource(
resource_data = dict(
package=package,
path=path,
name=name,
Expand All @@ -235,7 +235,11 @@ def index_package_files(package, scan_data):
is_key_file=is_key_file,
is_file=is_file,
)
r.set_scan_results(resource, save=True)
r, r_created = Resource.objects.get_or_create(
**resource_data
)
if r_created or overwrite_fields:
r.set_scan_results(resource, save=True)

if sha1:
_, _ = ExactFileIndex.index(
Expand Down

0 comments on commit 00021b2

Please sign in to comment.