Skip to content

Commit

Permalink
bug in completion for first page when no limit was set
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgirard committed Sep 1, 2017
1 parent 6df38c6 commit bdc4429
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions server/routes/editLog.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function getEditLog(req, res){
else
mongoQuery['date']= {'$lte': endDate}
}
const aggregationPipeline = [
let aggregationPipeline = [
{'$match':mongoQuery},
{'$lookup':{
from: 'people',
Expand Down Expand Up @@ -181,14 +181,23 @@ function getEditLog(req, res){
async.whilst(() => query.limit && edits.length < data.length,
(nextWhilst) =>{
// ask for next edits to replace the filtered ones
aggregationPipeline.forEach(s => { if (s['$skip']) s['$skip']+= +query.limit})
let skip = aggregationPipeline.find(p => p['$skip'])
if(skip)
skip += query.limit
else{
let limitIndex = aggregationPipeline.findIndex(p => p['$limit'])
aggregationPipeline = aggregationPipeline.slice(0,limitIndex)
.concat([{ '$skip' : +query.limit}]
.concat(aggregationPipeline.slice(limitIndex)))
}
EditLog.aggregate(aggregationPipeline)
.then(newData => {
debug(`added ${data.length - edits.length} more edits to reach ${data.length}`)
const newEdits = formatEdits(newData, model)
// fastforward: add the number filtered edits and substract the unfiltered but not included in response
fastforward += newData.length - newEdits.length + newEdits.length - data.length + edits.length
edits = edits.concat(newEdits.slice(0,data.length - edits.length))
debug(edits.length)
nextWhilst(null)
})
},
Expand Down

0 comments on commit bdc4429

Please sign in to comment.