Skip to content

Commit

Permalink
Allows fetching user events blockwise with a default duplicate preven…
Browse files Browse the repository at this point in the history
…ter.

Fixes: SE-14230
  • Loading branch information
fhaScireum committed Dec 10, 2024
1 parent 198ac89 commit 612f676
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/main/java/sirius/biz/analytics/events/EventRecorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,25 @@ protected Event<?> fetchBufferedEvent() {
return result;
}

/**
* Fetches all user events which match the given query.
* <p>
* Duplicates are prevented by assuming that users do not generate multiple events of the same type at the same
* time.
*
* @param query the query to execute
* @param <E> the type of the events to fetch
* @return a stream of events which match the given query
*/
public <E extends Event<E> & UserEvent> Stream<E> fetchUserEventsBlockwise(SmartQuery<E> query) {
return StreamSupport.stream(new EventSpliterator<E>(query, (effectiveQuery, lastEvent) -> {
query.where(OMA.FILTERS.not(OMA.FILTERS.and(OMA.FILTERS.eq(Event.EVENT_TIMESTAMP,
lastEvent.getEventTimestamp()),
OMA.FILTERS.eq(UserEvent.USER_DATA.inner(UserData.USER_ID),
lastEvent.getUserData().getUserId()))));
}), false);
}

/**
* Fetches all events which match the given query considering the given duplicate preventer.
*
Expand Down

0 comments on commit 612f676

Please sign in to comment.