Skip to content

Commit

Permalink
lwc-events: add pre-filter method for events (#1672)
Browse files Browse the repository at this point in the history
Add `couldMatch` method to the client to allow for filtering
our some data early if it requires an expensive transform to
generate the final event.
  • Loading branch information
brharrington authored Jul 10, 2024
1 parent b5e86a8 commit 055b549
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ abstract class AbstractLwcEventClient(clock: Clock) extends LwcEventClient {
Query.simplify(q, ignore = true)
}

override def couldMatch(tags: String => String): Boolean = {
index.couldMatch(k => tags(k))
}

override def process(event: LwcEvent): Unit = {
event match {
case LwcEvent.HeartbeatLwcEvent(timestamp) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ import scala.util.Using
*/
trait LwcEventClient {

/**
* Check if an event with a partial set of tags could match one of the expressions.
* This can be used as a pre-filter for cases where an expensive transform is required
* to generate the final event for consideration.
*
* @param tags
* Function that returns the tag value for a given key, or `null` if there is no
* value for that key. This tag set may be a subset of the final set of tags that
* would be on the actual events.
* @return
* True if an event with the partial set of tags might match one of the current
* expressions.
*/
def couldMatch(tags: String => String): Boolean

/**
* Submit an event for a given subscription.
*
Expand Down
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object Dependencies {
val log4j = "2.23.1"
val scala = "2.13.14"
val slf4j = "1.7.36"
val spectator = "1.7.14"
val spectator = "1.7.16"
val spring = "6.1.10"

val crossScala = Seq(scala, "3.4.1")
Expand Down

0 comments on commit 055b549

Please sign in to comment.