mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-11 18:32:20 +08:00
Optimize offsetOfId, shouldn't throw if models contains undefined
This commit is contained in:
parent
6c559ddb7e
commit
ffb5e0dfda
1 changed files with 7 additions and 1 deletions
|
@ -78,7 +78,13 @@ class QueryResultSet
|
||||||
@_modelsHash[id]
|
@_modelsHash[id]
|
||||||
|
|
||||||
offsetOfId: (id) ->
|
offsetOfId: (id) ->
|
||||||
idx = _.findIndex @models(), (m) -> m.id is id or m.clientId is id
|
idx = @_ids.indexOf(id)
|
||||||
|
|
||||||
|
# If we can't find the item, try to match against client ids as well. Some
|
||||||
|
# items in the models() array may not be loaded, but we can try our best.
|
||||||
|
if idx is -1
|
||||||
|
idx = _.findIndex @models(), (m) -> m and (m.id is id or m.clientId is id)
|
||||||
|
|
||||||
return -1 if idx is -1
|
return -1 if idx is -1
|
||||||
return @_offset + idx
|
return @_offset + idx
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue