https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42877

--- Comment #1 from Martin Renvoize (ashimema) 
<[email protected]> ---
Created attachment 200640
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=200640&action=edit
Bug 42877: Memoize _get_marc_mapping_rules to speed up record indexing

_get_marc_mapping_rules rebuilds a large rules hashref on every call by
iterating all search field mappings and parsing MARC field expressions (~10.7
ms per call). marc_records_to_documents calls it once per call, so every
single-record indexing job (each AddBiblio/ModBiblio enqueues a job that
indexes one record) pays the full rebuild for that one record -- roughly 75%
of that job's CPU.

This caches the compiled rules at the package level, keyed by marcflavour and
index (e.g. 'marc21.biblios'), built once per combination and reused. The
existing '# TODO' in _get_marc_mapping_rules already noted this could be
cached.

Cache invalidation: clear_search_fields_cache() clears the rules cache. Like
the existing mapping cache in _foreach_mapping (state %all_mappings), the rules
cache is per-process and is not auto-invalidated when search mappings change at
runtime -- clear_search_fields_cache must be called (as the mapping-edit paths
already require, and a reindex is needed for mapping changes regardless). This
patch therefore introduces no new staleness beyond what already exists.

Test plan:
1. prove t/db_dependent/Koha/SearchEngine/Elasticsearch.t
2. Confirm _get_marc_mapping_rules returns the cached reference on the second
   call, and that clear_search_fields_cache forces a rebuild.
3. Optionally benchmark a single-record index (edit a biblio) before/after.

-- 
You are receiving this mail because:
You are watching all bug changes.
_______________________________________________
Koha-bugs mailing list
[email protected]
https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-bugs
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to