@@ -55,8 +55,15 @@ class Collections(system: ExtendedActorSystem) extends Actor with ActorLogging {
55
55
verifiedNames.clear()
56
56
promisedDone success Done
57
57
58
- case GetJournals (response) =>
59
- val collections = database.flatMap(_.collectionNames.map(_.filter(_.startsWith(journalPrefix))).flatMap { names =>
58
+ case GetJournals (response, collectionNames) =>
59
+ val collections = database.flatMap(_
60
+ .collectionNames.map { allNames =>
61
+ val journalNames = allNames.filter(_.startsWith(journalPrefix))
62
+ collectionNames match {
63
+ case Nil => journalNames
64
+ case _ => journalNames.filter(name => collectionNames.exists(colName => name.endsWith(colName)))
65
+ }
66
+ }.flatMap { names =>
60
67
Future .traverse(names) { name =>
61
68
val promisedCollection = Promise [BSONCollection ]
62
69
promisedCollection completeWith verifiedJournalCollection(name)
@@ -67,7 +74,7 @@ class Collections(system: ExtendedActorSystem) extends Actor with ActorLogging {
67
74
68
75
case CheckHealth (ack) =>
69
76
val collections = Promise [List [BSONCollection ]]
70
- context.self ! GetJournals (collections)
77
+ context.self ! GetJournals (collections, Nil )
71
78
val eventualDone = collections.future.map(_.headOption).flatMap {
72
79
case Some (collection) => collection.find(BSONDocument .empty).one.map(_ => Done )
73
80
case None => Future .successful(Done )
@@ -162,10 +169,16 @@ class Collections(system: ExtendedActorSystem) extends Actor with ActorLogging {
162
169
}
163
170
164
171
private def ensureTagIndex (indexesManager : CollectionIndexesManager ): Future [Unit ] = {
165
- ensureIndex(index(Seq (
172
+ val tagsById = ensureIndex(index(Seq (
166
173
" _id" -> IndexType .Ascending ,
167
174
Fields .tags -> IndexType .Ascending ,
168
- ), Some (" _tags" ), unique = true , sparse = true ), indexesManager)
175
+ ), Some (" tags_by_id" ), unique = true , sparse = true ), indexesManager)
176
+
177
+ val allTags = ensureIndex(index(Seq (
178
+ Fields .tags -> IndexType .Ascending ,
179
+ ), Some (" tags" ), sparse = true ), indexesManager)
180
+
181
+ tagsById flatMap (_ => allTags)
169
182
}
170
183
171
184
private def ensureIndex (index : Aux [BSONSerializationPack .type ], indexesManager : CollectionIndexesManager ): Future [Unit ] = {
@@ -209,7 +222,7 @@ object Collections {
209
222
210
223
case class GetSnapshotCollectionNameFor (persistentId : String , response : Promise [BSONCollection ]) extends Command
211
224
212
- case class GetJournals (response : Promise [List [BSONCollection ]]) extends Command
225
+ case class GetJournals (response : Promise [List [BSONCollection ]], collectionNames : List [ String ] ) extends Command
213
226
214
227
case class SetDatabaseProvider (databaseProvider : DatabaseProvider , ack : Promise [Done ]) extends Command
215
228
0 commit comments