Do not spit out warns on invalid tile unload (preemtive working cache deletion), do not ignore working cache even if __restore=true.

This commit is contained in:
Aiosa 2024-10-21 09:00:24 +02:00
parent b3cdeabf02
commit 68f0ed8901
3 changed files with 14 additions and 15 deletions

View File

@ -539,7 +539,7 @@ $.Tile.prototype = {
*/ */
setData: function(value, type) { setData: function(value, type) {
if (!this.tiledImage) { if (!this.tiledImage) {
return null; //async context can access the tile outside its lifetime return Promise.resolve(); //async context can access the tile outside its lifetime
} }
let cache = this.getCache(this._wcKey); let cache = this.getCache(this._wcKey);
@ -594,7 +594,8 @@ $.Tile.prototype = {
//TODO IMPLEMENT LOCKING AND IGNORE PIPELINE OUT OF THESE CALLS //TODO IMPLEMENT LOCKING AND IGNORE PIPELINE OUT OF THESE CALLS
// Now, if working cache exists, we set main cache to the working cache, since it has been updated // Now, if working cache exists, we set main cache to the working cache, since it has been updated
const cache = !requestedRestore && this.getCache(this._wcKey); // if restore() was called last, then working cache was deleted (does not exist)
const cache = this.getCache(this._wcKey);
if (cache) { if (cache) {
let newCacheKey = this.cacheKey === this.originalCacheKey ? "mod://" + this.originalCacheKey : this.cacheKey; let newCacheKey = this.cacheKey === this.originalCacheKey ? "mod://" + this.originalCacheKey : this.cacheKey;
this.tiledImage._tileCache.consumeCache({ this.tiledImage._tileCache.consumeCache({
@ -745,7 +746,7 @@ $.Tile.prototype = {
removeCache: function(key, freeIfUnused = true) { removeCache: function(key, freeIfUnused = true) {
if (!this._caches[key]) { if (!this._caches[key]) {
// try to erase anyway in case the cache got stuck in memory // try to erase anyway in case the cache got stuck in memory
this.tiledImage._tileCache.unloadCacheForTile(this, key, freeIfUnused); this.tiledImage._tileCache.unloadCacheForTile(this, key, freeIfUnused, true);
return; return;
} }
@ -771,7 +772,7 @@ $.Tile.prototype = {
return; return;
} }
} }
if (this.tiledImage._tileCache.unloadCacheForTile(this, key, freeIfUnused)) { if (this.tiledImage._tileCache.unloadCacheForTile(this, key, freeIfUnused, false)) {
//if we managed to free tile from record, we are sure we decreased cache count //if we managed to free tile from record, we are sure we decreased cache count
delete this._caches[key]; delete this._caches[key];
} }

View File

@ -186,8 +186,8 @@
let internalCache = this[DRAWER_INTERNAL_CACHE]; let internalCache = this[DRAWER_INTERNAL_CACHE];
internalCache = internalCache && internalCache[drawer.getId()]; internalCache = internalCache && internalCache[drawer.getId()];
if (keepInternalCopy && !internalCache) { if (keepInternalCopy && !internalCache) {
$.console.warn("Attempt to render tile that is not prepared with drawer requesting " + $.console.warn("Attempt to render tile cache %s that is not prepared with drawer requesting " +
"internal cache! This might introduce artifacts."); "internal cache! This might introduce artifacts.", this);
this.prepareForRendering(drawer.getId(), supportedTypes, keepInternalCopy) this.prepareForRendering(drawer.getId(), supportedTypes, keepInternalCopy)
.then(() => this._triggerNeedsDraw()); .then(() => this._triggerNeedsDraw());
@ -207,8 +207,8 @@
} }
if (!supportedTypes.includes(internalCache.type)) { if (!supportedTypes.includes(internalCache.type)) {
$.console.warn("Attempt to render tile that is not prepared for current drawer supported format: " + $.console.warn("Attempt to render tile cache %s that is not prepared for current drawer " +
"the preparation should've happened after tile processing has finished."); "supported format: the preparation should've happened after tile processing has finished.", this);
internalCache.transformTo(supportedTypes.length > 1 ? supportedTypes : supportedTypes[0]) internalCache.transformTo(supportedTypes.length > 1 ? supportedTypes : supportedTypes[0])
.then(() => this._triggerNeedsDraw()); .then(() => this._triggerNeedsDraw());
@ -1096,9 +1096,10 @@
* @param {OpenSeadragon.Tile} tile * @param {OpenSeadragon.Tile} tile
* @param {string} key cache key * @param {string} key cache key
* @param {boolean} destroy if true, empty cache is destroyed, else left as a zombie * @param {boolean} destroy if true, empty cache is destroyed, else left as a zombie
* @param {boolean} okIfNotExists sometimes we call destruction just to make sure, if true do not report as error
* @private * @private
*/ */
unloadCacheForTile(tile, key, destroy) { unloadCacheForTile(tile, key, destroy, okIfNotExists) {
const cacheRecord = this._cachesLoaded[key]; const cacheRecord = this._cachesLoaded[key];
//unload record only if relevant - the tile exists in the record //unload record only if relevant - the tile exists in the record
if (cacheRecord) { if (cacheRecord) {
@ -1122,7 +1123,9 @@
"does not belong to! This could mean a bug in the cache system."); "does not belong to! This could mean a bug in the cache system.");
return false; return false;
} }
$.console.warn("[TileCache.unloadCacheForTile] Attempting to delete missing cache!"); if (!okIfNotExists) {
$.console.warn("[TileCache.unloadCacheForTile] Attempting to delete missing cache!");
}
return false; return false;
} }

View File

@ -79,10 +79,5 @@
</section> </section>
<script src="demo.js"></script> <script src="demo.js"></script>
<!-- Google analytics -->
<script async type="text/javascript" id="_fed_an_ua_tag" src="https://dap.digitalgov.gov/Universal-Federated-Analytics-Min.js?agency=NIST&subagency=github&pua=UA-66610693-1&yt=true&exts=ppsx,pps,f90,sch,rtf,wrl,txz,m1v,xlsm,msi,xsd,f,tif,eps,mpg,xml,pl,xlt,c">
</script>
</body> </body>
</html> </html>