Skip to content

Commit

Permalink
Update index only when needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvarner committed May 2, 2024
1 parent bed0a7e commit 1f7948a
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dev-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ jobs:
ruby-version: "2.7.2"

- name: Setup Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: "18.12"
node-version: "20"

- name: Install system requirements
run: |
Expand Down
2 changes: 1 addition & 1 deletion apps/iiif/annotations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def save(self, *args, **kwargs):
# if not self.content or self.content.isspace():
# raise ValidationError('Content cannot be empty')
# self.content = ' '
super(Annotation, self).save(*args, **kwargs)
super().save(*args, **kwargs)

class Meta: # pylint: disable=too-few-public-methods, missing-class-docstring
ordering = ['order']
Expand Down
6 changes: 6 additions & 0 deletions apps/iiif/canvases/tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,9 @@ def test_setting_height_and_width(self):
canvas.save()
assert canvas.height == 3000
assert canvas.width == 3000

def test_setting_resource(self):
canvas = CanvasNoDimensionsFactory.build(manifest=ManifestFactory.create())
assert canvas.resource is None
canvas.before_save()
assert canvas.resource == canvas.pid
7 changes: 7 additions & 0 deletions apps/iiif/manifests/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from import_export.widgets import ManyToManyWidget, ForeignKeyWidget
from django_summernote.admin import SummernoteModelAdmin
from .models import Manifest, Note, ImageServer, RelatedLink
from .documents import ManifestDocument
from .forms import ManifestAdminForm
from .views import AddToCollectionsView, MetadataImportView
from ..kollections.models import Collection
Expand Down Expand Up @@ -84,6 +85,12 @@ def get_urls(self):
]
return my_urls + urls

def save_model(self, request, obj, form, change):
# Add/update Volume in the Elasticsearch index.
index = ManifestDocument()
index.update(obj, True, 'index')
super().save_model(request, obj, form, change)

class NoteAdmin(admin.ModelAdmin):
"""Django admin configuration for a note."""
class Meta: # pylint: disable=too-few-public-methods, missing-class-docstring
Expand Down
6 changes: 6 additions & 0 deletions apps/iiif/manifests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,14 @@ def delete(self, *args, **kwargs):
for canvas in self.canvas_set.all():
canvas.delete()

# Delete from Elasticsearch index
from .documents import ManifestDocument
index = ManifestDocument()
index.update(self, True, 'delete')

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


def __rename_s3_objects(self):
original_pid = self.get_dirty_fields()['pid']
keys = [f.key for f in self.image_server.bucket.objects.filter(Prefix=f'{original_pid}/')]
Expand Down
14 changes: 13 additions & 1 deletion apps/readux/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.dispatch import receiver
from apps.iiif.annotations.models import AbstractAnnotation, Annotation
from apps.iiif.canvases.models import Canvas

from apps.iiif.manifests.documents import ManifestDocument
class TaggedUserAnnotations(TaggedItemBase):
"""Model for tagging :class:`UserAnnotation`s using Django Taggit."""
content_object = models.ForeignKey('UserAnnotation', on_delete=models.CASCADE)
Expand Down Expand Up @@ -60,6 +60,18 @@ def tag_list(self):
else:
return []

def save(self, *args, **kwargs):
if self.canvas:
index = ManifestDocument()
index.update(self.canvas.manifest, True, 'index')
super().save(*args, **kwargs)

def delete(self, *args, **kwargs):
if self.canvas:
index = ManifestDocument()
index.update(self.canvas.manifest, True, 'delete')
super().delete(*args, **kwargs)

def update(self, attrs=None, tags=None):
"""Method to update an annotation object with a dict of attributes and a list of tags
Expand Down

0 comments on commit 1f7948a

Please sign in to comment.