Skip to content

Commit

Permalink
documents: fix poor performance on serializer
Browse files Browse the repository at this point in the history
* Removes the files permissions for the document list serializer.

Co-Authored-by: Johnny Mariéthoz <Johnny.Mariethoz@rero.ch>
  • Loading branch information
jma committed Oct 10, 2023
1 parent 8be4064 commit 7ee3c4d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
4 changes: 2 additions & 2 deletions sonar/config_sonar.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,11 +608,11 @@
'organisations': {
'unifr': {
'types': ['coar:c_db06'],
'code': 6
'code': 2
},
'usi': {
'types': ['coar:c_db06'],
'code': 1
'code': 6
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions sonar/modules/documents/marshmallow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from __future__ import absolute_import, print_function

from .json import DocumentMetadataSchemaV1, DocumentSchemaV1
from .json import DocumentListSchemaV1, DocumentMetadataSchemaV1, \
DocumentSchemaV1

__all__ = ('DocumentMetadataSchemaV1', 'DocumentSchemaV1',)
__all__ = ('DocumentMetadataSchemaV1', 'DocumentSchemaV1', 'DocumentListSchemaV1')
18 changes: 16 additions & 2 deletions sonar/modules/documents/marshmallow/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def remove_fields(self, data, **kwargs):
return data


class DocumentMetadataSchemaV1(StrictKeysMixin):
class DocumentListMetadataSchemaV1(StrictKeysMixin):
"""Schema for the document metadata."""

pid = PersistentIdentifier()
Expand Down Expand Up @@ -141,7 +141,6 @@ class DocumentMetadataSchemaV1(StrictKeysMixin):
customField3 = fields.List(fields.String(validate=validate.Length(min=1)))
masked = SanitizedUnicode()
_bucket = SanitizedUnicode()
_files = Nested(FileSchemaV1, many=True)
_oai = fields.Dict()
# When loading, if $schema is not provided, it's retrieved by
# Record.schema property.
Expand Down Expand Up @@ -283,10 +282,25 @@ def remove_fields(self, data, **kwargs):
return data


class DocumentMetadataSchemaV1(DocumentListMetadataSchemaV1):
"""Schema for the document metadata."""

_files = Nested(FileSchemaV1, many=True)


class DocumentSchemaV1(StrictKeysMixin):
"""Document schema."""

id = PersistentIdentifier()
metadata = fields.Nested(DocumentMetadataSchemaV1)
links = fields.Dict(dump_only=True)
explanation = fields.Raw(dump_only=True)


class DocumentListSchemaV1(StrictKeysMixin):
"""Document schema."""

id = PersistentIdentifier()
metadata = fields.Nested(DocumentListMetadataSchemaV1)
links = fields.Dict(dump_only=True)
explanation = fields.Raw(dump_only=True)
5 changes: 3 additions & 2 deletions sonar/modules/documents/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from invenio_records_rest.serializers.response import record_responsify, \
search_responsify

from ..marshmallow import DocumentSchemaV1
from ..marshmallow import DocumentListSchemaV1, DocumentSchemaV1
from .dc import DublinCoreSerializer
from .google_scholar import SonarGoogleScholarSerializer
from .json import JSONSerializer
Expand All @@ -32,6 +32,7 @@
# ===========
#: JSON serializer definition.
json_v1 = JSONSerializer(DocumentSchemaV1)
json_list_v1 = JSONSerializer(DocumentListSchemaV1)
#: schema.org serializer
schemaorg_v1 = SonarSchemaOrgSerializer(SchemaOrgV1, replace_refs=True)
#: google scholar serializer
Expand All @@ -46,7 +47,7 @@
#: JSON record serializer for individual records.
json_v1_response = record_responsify(json_v1, 'application/json')
#: JSON record serializer for search results.
json_v1_search = search_responsify(json_v1, 'application/json')
json_v1_search = search_responsify(json_list_v1, 'application/json')

#: JSON record serializer for individual records.
dc_v1_response = record_responsify(dc_v1, 'text/xml')
Expand Down

0 comments on commit 7ee3c4d

Please sign in to comment.