Skip to content

Commit

Permalink
Limit consecutive caches in BioOntResults
Browse files Browse the repository at this point in the history
Slows down everything if called too often

Issue #1654
  • Loading branch information
robyngit committed Sep 4, 2024
1 parent 082cbb7 commit c2bdadb
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/js/collections/ontologies/BioontologyResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ define([
const ONTOLOGY_TYPE = "http://data.bioontology.org/metadata/Ontology";
// The number of items to remove from the cache if it is full
const CACHE_REMOVAL_SIZE = 100;
// The number of milliseconds to wait before caching new items
const CACHE_DEBOUNCE_TIME = 500;
/**
* @class BioontologyResults
* @classdesc A collection of items returned from the BioPortal API. So far
Expand Down Expand Up @@ -43,6 +45,7 @@ define([
* @param {boolean} [options.autoCache] - Whether to automatically cache new items
*/
initialize(_attributes, options) {
this.cache = _.debounce(this.cache, CACHE_DEBOUNCE_TIME);
if (options?.autoCache !== false) {
this.listenTo(this, "add", this.cache);
}
Expand Down

0 comments on commit c2bdadb

Please sign in to comment.