Skip to content

Commit 32f5a55

Browse files
committed
Fix average size calc error #202
1 parent 6fe5fef commit 32f5a55

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/virtual.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,14 @@ export default class Virtual {
104104
}
105105

106106
// calculate the average size only in the first range
107-
if (this.sizes.size <= this.param.keeps) {
108-
this.firstRangeTotalSize = this.firstRangeTotalSize + size
109-
this.firstRangeAverageSize = Math.round(this.firstRangeTotalSize / this.sizes.size)
110-
} else {
111-
// it's done using
112-
delete this.firstRangeTotalSize
107+
if (this.calcType !== CALC_TYPE.FIXED && typeof this.firstRangeTotalSize !== 'undefined') {
108+
if (this.sizes.size < Math.min(this.param.keeps, this.param.uniqueIds.length)) {
109+
this.firstRangeTotalSize = this.firstRangeTotalSize + size
110+
this.firstRangeAverageSize = Math.round(this.firstRangeTotalSize / this.sizes.size)
111+
} else {
112+
// it's done using
113+
delete this.firstRangeTotalSize
114+
}
113115
}
114116
}
115117

@@ -303,6 +305,6 @@ export default class Virtual {
303305

304306
// get the item estimate size
305307
getEstimateSize () {
306-
return this.firstRangeAverageSize || this.param.estimateSize
308+
return this.isFixedType() ? this.fixedSizeValue : (this.firstRangeAverageSize || this.param.estimateSize)
307309
}
308310
}

0 commit comments

Comments
 (0)