* _validateEntitiesAsync * Schedule validation for many entities. * This may take time but happen in the background during browser idle time. * @param {ValidationCache} cache - The cache to store results in (`_head` or `_base`) * @param {Array|Set} entityIDs - The entityIDs
(cache, entityIDs)
| 710 | * @return {Promise} Promise fulfilled when the validation has completed. |
| 711 | */ |
| 712 | _validateEntitiesAsync(cache, entityIDs) { |
| 713 | // Enqueue the work |
| 714 | const jobs = Array.from(entityIDs).map(entityID => { |
| 715 | if (cache.queuedEntityIDs.has(entityID)) return null; // queued already |
| 716 | cache.queuedEntityIDs.add(entityID); |
| 717 | |
| 718 | // Clear caches for existing issues related to this entity |
| 719 | cache.uncacheEntityID(entityID); |
| 720 | |
| 721 | return () => { |
| 722 | cache.queuedEntityIDs.delete(entityID); |
| 723 | |
| 724 | const graph = cache.graph; |
| 725 | if (!graph) return; // was reset? |
| 726 | |
| 727 | const entity = graph.hasEntity(entityID); // Sanity check: don't validate deleted entities |
| 728 | if (!entity) return; |
| 729 | |
| 730 | // detect new issues and update caches |
| 731 | const result = this._validateEntity(entity, graph); |
| 732 | if (result.provisional) { // provisional result |
| 733 | cache.provisionalEntityIDs.add(entityID); // we'll need to revalidate this entity again later |
| 734 | } |
| 735 | |
| 736 | cache.cacheIssues(result.issues); // update cache |
| 737 | }; |
| 738 | |
| 739 | }).filter(Boolean); |
| 740 | |
| 741 | // Perform the work in chunks. |
| 742 | // Because this will happen during idle callbacks, we want to choose a chunk size |
| 743 | // that won't make the browser stutter too badly. |
| 744 | cache.queue = cache.queue.concat(utilArrayChunk(jobs, 50)); |
| 745 | |
| 746 | // Enqueue the work |
| 747 | if (!cache.queuePromise) { |
| 748 | cache.queuePromise = this._processQueue(cache) |
| 749 | .then(() => this._revalidateProvisionalEntities(cache)) |
| 750 | .catch(e => console.error(e)) // eslint-disable-line |
| 751 | .finally(() => cache.queuePromise = null); |
| 752 | } |
| 753 | |
| 754 | return cache.queuePromise; |
| 755 | } |
| 756 | |
| 757 | |
| 758 | /** |
no test coverage detected