Skip to content

Commit

Permalink
items: improve response time for csv export
Browse files Browse the repository at this point in the history
The CSV export of the inventory list has an important waiting time.
With this commit, we try to improve the response time.

* Uses ciso8601 to parse date fields instead `format_date_filter`.
* Adds new api endpoint for inventory list.
* Uses streaming to process download csv file.
* Uses bunch request to reduce elasticsearch calls.
* Adds some fields in csv file.
* Closes rero#1456.
* Closes rero#1329.

Co-Authored-by: Laurent Dubois <laurent.dubois@itld-solutions.be>
  • Loading branch information
lauren-d committed May 11, 2021
1 parent cb94dba commit 01beedd
Show file tree
Hide file tree
Showing 14 changed files with 374 additions and 184 deletions.
3 changes: 2 additions & 1 deletion rero_ils/modules/holdings/api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
from jinja2.exceptions import TemplateSyntaxError, UndefinedError
from werkzeug.exceptions import NotFound

from rero_ils.modules.views import check_authentication

from .api import Holding
from ..errors import RegularReceiveNotAllowed
from ..items.api_views import check_authentication
from ...permissions import can_receive_regular_issue

api_blueprint = Blueprint(
Expand Down
5 changes: 2 additions & 3 deletions rero_ils/modules/items/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
"""Item data module."""

from .api import Item, ItemsIndexer, ItemsSearch, item_id_fetcher, \
item_id_minter, search_active_loans_for_item
item_id_minter
from .circulation import ItemCirculation
from .issue import ItemIssue
from .record import ItemRecord

__all__ = (
'Item', 'ItemRecord', 'ItemCirculation', 'ItemIssue', 'ItemsSearch',
'ItemsIndexer', 'item_id_fetcher', 'item_id_minter',
'search_active_loans_for_item'
'ItemsIndexer', 'item_id_fetcher', 'item_id_minter'
)
21 changes: 0 additions & 21 deletions rero_ils/modules/items/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@
from functools import partial

from elasticsearch.exceptions import NotFoundError
from flask import current_app
from invenio_circulation.search.api import search_by_pid
from invenio_search import current_search

from .circulation import ItemCirculation
from .issue import ItemIssue
from ..models import ItemIdentifier, ItemMetadata
from ..utils import item_pid_to_object
from ...api import IlsRecordError, IlsRecordsIndexer, IlsRecordsSearch
from ...documents.api import Document, DocumentsSearch
from ...fetchers import id_fetcher
Expand All @@ -50,24 +47,6 @@
item_id_fetcher = partial(id_fetcher, provider=ItemProvider)


def search_active_loans_for_item(item_pid):
"""Return count and all active loans for an item."""
item_pid_object = item_pid_to_object(item_pid)
states = ['PENDING'] + \
current_app.config['CIRCULATION_STATES_LOAN_ACTIVE']
search = search_by_pid(
item_pid=item_pid_object,
filter_states=states,
sort_by_field='_created',
sort_order='desc'
)
loans_count = search.count()
try:
return loans_count, search.scan()
except StopIteration:
return loans_count


class ItemsSearch(IlsRecordsSearch):
"""ItemsSearch."""

Expand Down
6 changes: 5 additions & 1 deletion rero_ils/modules/items/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ def enrich_item_data(sender, json=None, record=None, index=None,
json['vendor'] = {
'pid': item.vendor_pid
}

# inherited_first_call_number to issue
inherited_first_call_number = item.issue_inherited_first_call_number
if inherited_first_call_number:
json['issue']['inherited_first_call_number'] = \
inherited_first_call_number
# Local fields in JSON
local_fields = LocalField.get_local_fields_by_resource(
'item', item.pid)
Expand Down
3 changes: 3 additions & 0 deletions rero_ils/modules/items/mappings/v7/items/item-v0.0.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@
"status": {
"type": "keyword"
},
"inherited_first_call_number": {
"type": "keyword"
},
"status_date": {
"type": "date"
},
Expand Down
7 changes: 7 additions & 0 deletions rero_ils/modules/items/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,10 @@ class ItemNoteTypes:
CONDITION,
PATRIMONIAL
]

INVENTORY_LIST_CATEGORY = [
GENERAL,
STAFF,
CHECKIN,
CHECKOUT
]
15 changes: 14 additions & 1 deletion rero_ils/modules/items/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,28 @@
'document_creator',
'document_main_type',
'document_sub_type',
'library_name',
'location_name',
'barcode',
'call_number',
'second_call_number',
'enumerationAndChronology',
'item_type',
'temporary_item_type',
'temporary_item_type_end_date',
'general_note',
'staff_note',
'checkin_note',
'checkout_note',
'loans_count',
'last_transaction_date',
'status',
'created'
'created',
'issue_status',
'issue_status_date',
'issue_claims_count',
'issue_expected_date',
'issue_regular'
]
)
csv_item_response = record_responsify(csv_item, "text/csv")
Expand Down
Loading

0 comments on commit 01beedd

Please sign in to comment.