[icalendar] optimization of eventfilter-search and more debug output (#9501)
* [icalendar] Optimize searching events and adding a bit debug output Fixes #9498 by limiting series events when retrieving possible events via filter. Adding a bit more debug output to allow debugging the correct scheduling of events. Signed-off-by: Michael Wodniok <michi@noorganization.org>
This commit is contained in:
parent
6c86f8d366
commit
a7ac71f1e0
@ -266,6 +266,7 @@ public class ICalendarHandler extends BaseBridgeHandler implements CalendarUpdat
|
||||
* @return Whether the calendar was loaded successfully.
|
||||
*/
|
||||
private boolean reloadCalendar() {
|
||||
logger.trace("reloading calendar of {}", getThing().getUID());
|
||||
if (!calendarFile.isFile()) {
|
||||
logger.info("Local file for reloading calendar is missing.");
|
||||
return false;
|
||||
@ -314,6 +315,7 @@ public class ICalendarHandler extends BaseBridgeHandler implements CalendarUpdat
|
||||
ICalendarHandler.this.updateStates();
|
||||
ICalendarHandler.this.rescheduleCalendarStateUpdate();
|
||||
}, currentEvent.end.getEpochSecond() - now.getEpochSecond(), TimeUnit.SECONDS);
|
||||
logger.debug("Scheduled update in {} seconds", currentEvent.end.getEpochSecond() - now.getEpochSecond());
|
||||
} else {
|
||||
final Event nextEvent = currentCalendar.getNextEvent(now);
|
||||
final ICalendarConfiguration currentConfig = this.configuration;
|
||||
@ -326,11 +328,14 @@ public class ICalendarHandler extends BaseBridgeHandler implements CalendarUpdat
|
||||
updateJobFuture = scheduler.schedule(() -> {
|
||||
ICalendarHandler.this.rescheduleCalendarStateUpdate();
|
||||
}, 1L, TimeUnit.DAYS);
|
||||
logger.debug("Scheduled reschedule in 1 day");
|
||||
} else {
|
||||
updateJobFuture = scheduler.schedule(() -> {
|
||||
ICalendarHandler.this.updateStates();
|
||||
ICalendarHandler.this.rescheduleCalendarStateUpdate();
|
||||
}, nextEvent.start.getEpochSecond() - now.getEpochSecond(), TimeUnit.SECONDS);
|
||||
logger.debug("Scheduled update in {} seconds", nextEvent.start.getEpochSecond() - now.getEpochSecond());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -339,6 +344,7 @@ public class ICalendarHandler extends BaseBridgeHandler implements CalendarUpdat
|
||||
* Updates the states of the Thing and its channels.
|
||||
*/
|
||||
private void updateStates() {
|
||||
logger.trace("updating states of {}", getThing().getUID());
|
||||
final AbstractPresentableCalendar calendar = runtimeCalendar;
|
||||
if (calendar == null) {
|
||||
updateStatus(ThingStatus.OFFLINE);
|
||||
|
||||
@ -178,7 +178,7 @@ class BiweeklyPresentableCalendar extends AbstractPresentableCalendar {
|
||||
@Override
|
||||
public List<Event> getFilteredEventsBetween(Instant begin, Instant end, @Nullable EventTextFilter filter,
|
||||
int maximumCount) {
|
||||
List<VEventWPeriod> candidates = this.getVEventWPeriodsBetween(begin, end);
|
||||
List<VEventWPeriod> candidates = this.getVEventWPeriodsBetween(begin, end, maximumCount);
|
||||
final List<Event> results = new ArrayList<>(candidates.size());
|
||||
|
||||
if (filter != null) {
|
||||
@ -237,9 +237,10 @@ class BiweeklyPresentableCalendar extends AbstractPresentableCalendar {
|
||||
*
|
||||
* @param frameBegin Begin of the frame where to search events.
|
||||
* @param frameEnd End of the time frame where to search events.
|
||||
* @param maximumPerSeries Limit the results per series. Set to 0 for no limit.
|
||||
* @return All events which begin in the time frame.
|
||||
*/
|
||||
private List<VEventWPeriod> getVEventWPeriodsBetween(Instant frameBegin, Instant frameEnd) {
|
||||
private List<VEventWPeriod> getVEventWPeriodsBetween(Instant frameBegin, Instant frameEnd, int maximumPerSeries) {
|
||||
final List<VEvent> positiveEvents = new ArrayList<>();
|
||||
final List<VEvent> negativeEvents = new ArrayList<>();
|
||||
classifyEvents(positiveEvents, negativeEvents);
|
||||
@ -248,6 +249,7 @@ class BiweeklyPresentableCalendar extends AbstractPresentableCalendar {
|
||||
for (final VEvent positiveEvent : positiveEvents) {
|
||||
final DateIterator positiveBeginDates = getRecurredEventDateIterator(positiveEvent);
|
||||
positiveBeginDates.advanceTo(Date.from(frameBegin));
|
||||
int foundInSeries = 0;
|
||||
while (positiveBeginDates.hasNext()) {
|
||||
final Instant begInst = positiveBeginDates.next().toInstant();
|
||||
if (begInst.isAfter(frameEnd)) {
|
||||
@ -263,9 +265,17 @@ class BiweeklyPresentableCalendar extends AbstractPresentableCalendar {
|
||||
if (eventUid != null) {
|
||||
if (!isCounteredBy(begInst, eventUid, negativeEvents)) {
|
||||
eventList.add(resultingVEWP);
|
||||
foundInSeries++;
|
||||
if (maximumPerSeries != 0 && foundInSeries >= maximumPerSeries) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
eventList.add(resultingVEWP);
|
||||
foundInSeries++;
|
||||
if (maximumPerSeries != 0 && foundInSeries >= maximumPerSeries) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -151,6 +151,7 @@ public class BiweeklyPresentableCalendarTest {
|
||||
* This test checks for Events that have just begun or ended, and if so it checks for Command Tags
|
||||
* and checks if these tags are valid
|
||||
*/
|
||||
@SuppressWarnings("null")
|
||||
@Test
|
||||
public void testCommandTagCode() {
|
||||
List<Event> events = null;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user