mirror of
https://github.com/overleaf/overleaf.git
synced 2025-03-15 04:24:52 +00:00
avoid N+1 lookups in DocumentUpdaterHandler
This commit is contained in:
parent
953dba0ede
commit
ef68c6a531
2 changed files with 12 additions and 11 deletions
|
@ -233,22 +233,23 @@ module.exports = DocumentUpdaterHandler =
|
|||
_getRenameUpdates: (entityType, oldEntities, newEntities) ->
|
||||
updates = []
|
||||
|
||||
for oldEntity in oldEntities
|
||||
id = oldEntity[entityType]._id
|
||||
newEntity = _.find newEntities, (newEntity) ->
|
||||
newEntity[entityType]._id.toString() == id.toString()
|
||||
oldEntitiesHash = _.indexBy oldEntities, (entity) -> entity[entityType]._id.toString()
|
||||
newEntitiesHash = _.indexBy newEntities, (entity) -> entity[entityType]._id.toString()
|
||||
|
||||
for id, oldEntity of oldEntitiesHash
|
||||
newEntity = newEntitiesHash[id]
|
||||
|
||||
# renamed entities
|
||||
if newEntity.path != oldEntity.path
|
||||
updates.push
|
||||
id: id
|
||||
pathname: oldEntity.path
|
||||
newPathname: newEntity.path
|
||||
|
||||
for newEntity in newEntities
|
||||
id = newEntity[entityType]._id
|
||||
oldEntity = _.find oldEntities, (oldEntity) ->
|
||||
oldEntity[entityType]._id.toString() == id.toString()
|
||||
for id, newEntity of newEntitiesHash
|
||||
oldEntity = oldEntitiesHash[id]
|
||||
|
||||
# removed entities
|
||||
if !oldEntity?
|
||||
updates.push
|
||||
id: id
|
||||
|
|
|
@ -427,7 +427,7 @@ describe 'DocumentUpdaterHandler', ->
|
|||
@newFiles = []
|
||||
|
||||
docUpdates = [
|
||||
id: @docIdB,
|
||||
id: @docIdB.toString(),
|
||||
pathname: "/old_b"
|
||||
newPathname: "/new_b"
|
||||
]
|
||||
|
@ -449,7 +449,7 @@ describe 'DocumentUpdaterHandler', ->
|
|||
@newFiles = []
|
||||
|
||||
docUpdates = [
|
||||
id: @docId,
|
||||
id: @docId.toString(),
|
||||
pathname: "/foo"
|
||||
docLines: 'a\nb'
|
||||
url: undefined
|
||||
|
@ -472,7 +472,7 @@ describe 'DocumentUpdaterHandler', ->
|
|||
]
|
||||
|
||||
fileUpdates = [
|
||||
id: @fileId,
|
||||
id: @fileId.toString(),
|
||||
pathname: "/bar"
|
||||
url: 'filestore.example.com/file'
|
||||
docLines: undefined
|
||||
|
|
Loading…
Reference in a new issue