Skip to content

Commit

Permalink
Don't trigger re-index when Collection is saved
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvarner committed Jun 4, 2024
1 parent 6bca934 commit 900af5e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
7 changes: 2 additions & 5 deletions apps/iiif/manifests/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Django:
"published_date",
"viewingdirection",
]
related_models = [Collection, Canvas]
related_models = [Canvas]

class Meta:
# make Keyword type default for strings, for custom dynamically-mapped facet fields
Expand Down Expand Up @@ -168,9 +168,6 @@ def get_queryset(self):

def get_instances_from_related(self, related_instance):
"""Retrieving item to index from related objects"""
if isinstance(related_instance, Collection):
# many to many relationship
return related_instance.manifests.all()
elif isinstance(related_instance, Canvas):
if isinstance(related_instance, Canvas):
# many to many relationship
return related_instance.manifest
21 changes: 10 additions & 11 deletions apps/iiif/manifests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
from django.conf import settings
from edtf.fields import EDTFField
from apps.iiif.manifests.validators import validate_edtf
import config.settings.local as settings
from ..choices import Choices
from ..kollections.models import Collection
from..models import IiifBase
from .tasks import index_manifest_task, de_index_manifest_task
from .tasks import index_manifest_task

JSONEncoder_olddefault = JSONEncoder.default # pylint: disable = invalid-name

Expand Down Expand Up @@ -101,7 +100,7 @@ class Meta:

def __str__(self):
"""String representation of the language"""
return self.name
return str(self.name)

class ManifestManager(models.Manager): # pylint: disable = too-few-public-methods
"""Model manager for searches."""
Expand Down Expand Up @@ -328,7 +327,7 @@ def autocomplete_label(self):
return self.label

def __str__(self):
return self.label
return str(self.label)

# FIXME: This creates a circular dependency - Importing UserAnnotation here.
# Furthermore, we shouldn't have any of the IIIF apps depend on Readux. Need
Expand All @@ -346,19 +345,19 @@ def save(self, *args, **kwargs): # pylint: disable = arguments-differ
self.__rename_s3_objects()

try:
Canvas = apps.get_model('canvases.canvas')
canvas_model = apps.get_model('canvases.canvas')
if self.start_canvas is None and hasattr(self, 'canvas_set') and self.canvas_set.exists():
self.start_canvas = self.canvas_set.all().order_by('position').first()
Canvas.objects.filter(manifest=self).update(is_starting_page=False)
Canvas.objects.filter(pk=self.start_canvas.id).update(is_starting_page=True)
except Canvas.DoesNotExist:
canvas_model.objects.filter(manifest=self).update(is_starting_page=False)
canvas_model.objects.filter(pk=self.start_canvas.id).update(is_starting_page=True)
except canvas_model.DoesNotExist:
self.start_canvas = None

super().save(*args, **kwargs)

# for collection in self.collections.all():
# collection.modified_at = self.modified_at
# collection.save()
for collection in self.collections.all(): # pylint: disable = no-member
collection.modified_at = self.modified_at
collection.save()

if environ["DJANGO_ENV"] != 'test': # pragma: no cover
index_manifest_task.apply_async(args=[str(self.id)])
Expand Down

0 comments on commit 900af5e

Please sign in to comment.