Skip to content

Commit

Permalink
Add slight delay to clean feature cache
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Nov 6, 2018
1 parent 6b8a420 commit a30bba4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 30 deletions.
34 changes: 6 additions & 28 deletions src/JBrowse/Store/SeqFeature/BAM.js
Expand Up @@ -279,34 +279,12 @@ return declare( [ SeqFeatureStore, DeferredStatsMixin, DeferredFeaturesMixin, In
}).catch(errorCallback)
},


getPairedRanges( query, featCallback, errorCallback ) {
let seqName = query.ref || this.refSeq.name
seqName = this.browser.regularizeReferenceName( seqName );
this._deferred.features.then(() => {
this.bam.getRecordsForRange(seqName, query.start, query.end, {viewAsPairs: query.viewAsPairs})
.then(records => {
let min = Infinity;
let max = -Infinity;
Object.entries(this.featureCache).forEach(([k, v]) => {
if(v.get('start') > query.end) {
delete this.featureCache[k]
} else if(v.get('end') < query.start) {
delete this.featureCache[k]
}
})
for(let i = 0; i < records.length; i++) {
if(records[i]._get('start') < min) {
min = records[i]._get('start')
}
if(records[i]._get('end') > max) {
max = records[i]._get('end')
}
}

featCallback({ min, max })
}).catch(errorCallback)
}, errorCallback)
cleanFeatureCache(query) {
Object.entries(this.featureCache).forEach(([k, v]) => {
if((v.get('end') < query.start) || (v.get('start') > query.end)) {
delete this.featureCache[k]
}
})
},


Expand Down
10 changes: 8 additions & 2 deletions src/JBrowse/View/Track/Alignments2.js
Expand Up @@ -187,8 +187,14 @@ return declare( [ CanvasFeatureTrack, AlignmentsMixin ], {
})
}
this.fetchMap[str].then(() => {
supermethod.apply(this, [args])
this.store.cleanFeatureCache({ ref: this.refSeq.name, start: region.start, end: region.end })
let f = args.finishCallback
args.finishCallback = () => {
f()
setTimeout(() =>
this.store.cleanFeatureCache({ ref: this.refSeq.name, start: min, end: max }),
1000)
}
supermethod.call(this, args)
})
} else {
this.inherited(arguments);
Expand Down

0 comments on commit a30bba4

Please sign in to comment.