mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
use compound index to replace separate index for packs
This commit is contained in:
parent
0ba00a9eb7
commit
0532a4daaa
2 changed files with 13 additions and 10 deletions
|
@ -136,9 +136,7 @@ module.exports = MongoManager =
|
||||||
# For finding all updates that go into a diff for a doc
|
# For finding all updates that go into a diff for a doc
|
||||||
db.docHistory.ensureIndex { doc_id: 1, v: 1 }, { background: true }
|
db.docHistory.ensureIndex { doc_id: 1, v: 1 }, { background: true }
|
||||||
# For finding all updates that affect a project
|
# For finding all updates that affect a project
|
||||||
db.docHistory.ensureIndex { project_id: 1, "meta.end_ts": 1 }, { background: true }
|
db.docHistory.ensureIndex { project_id: 1, "meta.end_ts": 1, "meta.start_ts": -1 }, { background: true }
|
||||||
# For finding all packs that affect a project (use a sparse index so only packs are included)
|
|
||||||
db.docHistory.ensureIndex { project_id: 1, "pack.0.meta.end_ts": 1, "meta.end_ts": 1}, { background: true, sparse: true }
|
|
||||||
# For finding updates that don't yet have a project_id and need it inserting
|
# For finding updates that don't yet have a project_id and need it inserting
|
||||||
db.docHistory.ensureIndex { doc_id: 1, project_id: 1 }, { background: true }
|
db.docHistory.ensureIndex { doc_id: 1, project_id: 1 }, { background: true }
|
||||||
# For finding project meta-data
|
# For finding project meta-data
|
||||||
|
|
|
@ -178,20 +178,25 @@ module.exports = PackManager =
|
||||||
.find(tailQuery, projection)
|
.find(tailQuery, projection)
|
||||||
.sort(sort)
|
.sort(sort)
|
||||||
|
|
||||||
# now find any packs that overlap with the time window
|
# now find any packs that overlap with the time window from outside
|
||||||
|
# cutoff before
|
||||||
|
# --|-----wanted-range--|------------------ time=>
|
||||||
|
# |-------------|pack(end_ts)
|
||||||
|
#
|
||||||
|
# these were not picked up by the original query because
|
||||||
|
# end_ts>before but the beginning of the pack may be in the time range
|
||||||
overlapQuery = _.clone(query)
|
overlapQuery = _.clone(query)
|
||||||
if before? && cutoff?
|
if before? && cutoff?
|
||||||
overlapQuery['meta.end_ts'] = {"$gte": before}
|
overlapQuery['meta.end_ts'] = {"$gte": before}
|
||||||
overlapQuery['pack.0.meta.end_ts'] = {"$lte": before }
|
overlapQuery['meta.start_ts'] = {"$lte": before }
|
||||||
else if before? && not cutoff?
|
else if before? && not cutoff?
|
||||||
overlapQuery['meta.end_ts'] = {"$gte": before}
|
overlapQuery['meta.end_ts'] = {"$gte": before}
|
||||||
overlapQuery['pack.0.meta.end_ts'] = {"$lte": before }
|
overlapQuery['meta.start_ts'] = {"$lte": before }
|
||||||
else if not before? && cutoff?
|
else if not before? && cutoff?
|
||||||
overlapQuery['meta.end_ts'] = {"$gte": cutoff}
|
overlapQuery['meta.end_ts'] = {"$gte": cutoff} # we already have these??
|
||||||
overlapQuery['pack.0.meta.end_ts'] = {"$gte": 0 }
|
|
||||||
else if not before? && not cutoff?
|
else if not before? && not cutoff?
|
||||||
overlapQuery['meta.end_ts'] = {"$gte": 0 }
|
overlapQuery['meta.end_ts'] = {"$gte": 0 } # shouldn't happen??
|
||||||
overlapQuery['pack.0.meta.end_ts'] = {"$gte": 0 }
|
|
||||||
overlap = collection
|
overlap = collection
|
||||||
.find(overlapQuery, projection)
|
.find(overlapQuery, projection)
|
||||||
.sort(sort)
|
.sort(sort)
|
||||||
|
|
Loading…
Reference in a new issue