@@ -13,9 +13,9 @@ trait EventsQueries
13
13
extends akka.persistence.query.scaladsl.EventsByTagQuery
14
14
with akka.persistence.query.scaladsl.EventsByPersistenceIdQuery
15
15
with akka.persistence.query.scaladsl.CurrentEventsByTagQuery
16
- with akka.persistence.query.scaladsl.CurrentEventsByPersistenceIdQuery {
16
+ with akka.persistence.query.scaladsl.CurrentEventsByPersistenceIdQuery with CustomReadOps {
17
17
18
- this : ReactiveMongoScalaReadJournal =>
18
+ this : ReactiveMongoScalaReadJournalImpl =>
19
19
20
20
private val amountOfCores : Int = Runtime .getRuntime.availableProcessors()
21
21
@@ -69,16 +69,16 @@ trait EventsQueries
69
69
* Same as [[EventsQueries#currentEventsByTag]] but events aren't serialized, instead
70
70
* the `EventEnvelope` will contain the raw `BSONDocument`
71
71
*/
72
- def currentRawEventsByTag (tag : String , offset : Offset ): Source [EventEnvelope , NotUsed ] = {
72
+ override def currentRawEventsByTag (tag : String , offset : Offset ): Source [EventEnvelope , NotUsed ] = {
73
73
currentRawEventsByTag(Seq (tag), offset)
74
74
}
75
75
76
- def currentRawEventsByTag (tags : Seq [String ], offset : Offset ): Source [EventEnvelope , NotUsed ] = {
76
+ override def currentRawEventsByTag (tags : Seq [String ], offset : Offset ): Source [EventEnvelope , NotUsed ] = {
77
77
implicit val raw : (BSONDocument , BSONDocument ) => Future [BSONDocument ] = (_, rawPayload) => Future (rawPayload)
78
78
eventsByTagQuery(tags, offset)
79
79
}
80
80
81
- def currentEventsByTags (tags : Seq [String ], offset : Offset ): Source [EventEnvelope , NotUsed ] = {
81
+ override def currentEventsByTags (tags : Seq [String ], offset : Offset ): Source [EventEnvelope , NotUsed ] = {
82
82
eventsByTagQuery(tags, offset)
83
83
}
84
84
@@ -109,33 +109,29 @@ trait EventsQueries
109
109
}
110
110
111
111
private def buildFindEventsByTagsQuery (coll : collection.BSONCollection , offset : Offset , tags : Seq [String ]) = {
112
-
113
112
def query (field : String ) = BSONDocument (field -> BSONDocument (" $in" -> tags))
114
113
115
- import coll .aggregationFramework ._
116
-
117
- val $1stMatch = Match (query(Fields .tags) ++ filterByOffset(offset))
118
- val $unwind = UnwindField (Fields .events)
119
- val $2ndMatch = Match (query(s " ${Fields .events}. ${Fields .tags}" ))
120
-
121
114
coll
122
- .aggregateWith[BSONDocument ]()(_ => ($1stMatch, List ($unwind, $2ndMatch)))
115
+ .aggregateWith[BSONDocument ]()(framework =>
116
+ List (
117
+ framework.Match (query(Fields .tags) ++ filterByOffset(offset)),
118
+ framework.UnwindField (Fields .events),
119
+ framework.Match (query(s " ${Fields .events}. ${Fields .tags}" )),
120
+ ))
123
121
.documentSource()
124
122
}
125
123
126
124
private def buildFindEventsByIdQuery (coll : collection.BSONCollection , persistenceId : String , fromSequenceNr : Long , toSequenceNr : Long ) = {
127
- import coll .aggregationFramework ._
128
-
129
- val $match = Match (BSONDocument (
130
- Fields .persistenceId -> persistenceId,
131
- Fields .from_sn -> BSONDocument (" $gt" -> fromSequenceNr),
132
- Fields .to_sn -> BSONDocument (" $lte" -> toSequenceNr)
133
- ))
134
- val $unwind = UnwindField (Fields .events)
135
- val $sort = Sort (Ascending (s " ${Fields .events}. ${Fields .sequence}" ))
136
-
137
125
coll
138
- .aggregateWith[BSONDocument ]()(_ => ($match , List ($unwind, $sort)))
126
+ .aggregateWith[BSONDocument ]()(framework => List (
127
+ framework.Match (BSONDocument (
128
+ Fields .persistenceId -> persistenceId,
129
+ Fields .from_sn -> BSONDocument (" $gt" -> fromSequenceNr),
130
+ Fields .to_sn -> BSONDocument (" $lte" -> toSequenceNr)
131
+ )),
132
+ framework.UnwindField (Fields .events),
133
+ framework.Sort (framework.Ascending (s " ${Fields .events}. ${Fields .sequence}" ))
134
+ ))
139
135
.documentSource()
140
136
}
141
137
0 commit comments