[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.
|
* @return Whether the calendar was loaded successfully.
|
||||||
*/
|
*/
|
||||||
private boolean reloadCalendar() {
|
private boolean reloadCalendar() {
|
||||||
|
logger.trace("reloading calendar of {}", getThing().getUID());
|
||||||
if (!calendarFile.isFile()) {
|
if (!calendarFile.isFile()) {
|
||||||
logger.info("Local file for reloading calendar is missing.");
|
logger.info("Local file for reloading calendar is missing.");
|
||||||
return false;
|
return false;
|
||||||
@ -314,6 +315,7 @@ public class ICalendarHandler extends BaseBridgeHandler implements CalendarUpdat
|
|||||||
ICalendarHandler.this.updateStates();
|
ICalendarHandler.this.updateStates();
|
||||||
ICalendarHandler.this.rescheduleCalendarStateUpdate();
|
ICalendarHandler.this.rescheduleCalendarStateUpdate();
|
||||||
}, currentEvent.end.getEpochSecond() - now.getEpochSecond(), TimeUnit.SECONDS);
|
}, currentEvent.end.getEpochSecond() - now.getEpochSecond(), TimeUnit.SECONDS);
|
||||||
|
logger.debug("Scheduled update in {} seconds", currentEvent.end.getEpochSecond() - now.getEpochSecond());
|
||||||
} else {
|
} else {
|
||||||
final Event nextEvent = currentCalendar.getNextEvent(now);
|
final Event nextEvent = currentCalendar.getNextEvent(now);
|
||||||
final ICalendarConfiguration currentConfig = this.configuration;
|
final ICalendarConfiguration currentConfig = this.configuration;
|
||||||
@ -326,11 +328,14 @@ public class ICalendarHandler extends BaseBridgeHandler implements CalendarUpdat
|
|||||||
updateJobFuture = scheduler.schedule(() -> {
|
updateJobFuture = scheduler.schedule(() -> {
|
||||||
ICalendarHandler.this.rescheduleCalendarStateUpdate();
|
ICalendarHandler.this.rescheduleCalendarStateUpdate();
|
||||||
}, 1L, TimeUnit.DAYS);
|
}, 1L, TimeUnit.DAYS);
|
||||||
|
logger.debug("Scheduled reschedule in 1 day");
|
||||||
} else {
|
} else {
|
||||||
updateJobFuture = scheduler.schedule(() -> {
|
updateJobFuture = scheduler.schedule(() -> {
|
||||||
ICalendarHandler.this.updateStates();
|
ICalendarHandler.this.updateStates();
|
||||||
ICalendarHandler.this.rescheduleCalendarStateUpdate();
|
ICalendarHandler.this.rescheduleCalendarStateUpdate();
|
||||||
}, nextEvent.start.getEpochSecond() - now.getEpochSecond(), TimeUnit.SECONDS);
|
}, 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.
|
* Updates the states of the Thing and its channels.
|
||||||
*/
|
*/
|
||||||
private void updateStates() {
|
private void updateStates() {
|
||||||
|
logger.trace("updating states of {}", getThing().getUID());
|
||||||
final AbstractPresentableCalendar calendar = runtimeCalendar;
|
final AbstractPresentableCalendar calendar = runtimeCalendar;
|
||||||
if (calendar == null) {
|
if (calendar == null) {
|
||||||
updateStatus(ThingStatus.OFFLINE);
|
updateStatus(ThingStatus.OFFLINE);
|
||||||
|
|||||||
@ -178,7 +178,7 @@ class BiweeklyPresentableCalendar extends AbstractPresentableCalendar {
|
|||||||
@Override
|
@Override
|
||||||
public List<Event> getFilteredEventsBetween(Instant begin, Instant end, @Nullable EventTextFilter filter,
|
public List<Event> getFilteredEventsBetween(Instant begin, Instant end, @Nullable EventTextFilter filter,
|
||||||
int maximumCount) {
|
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());
|
final List<Event> results = new ArrayList<>(candidates.size());
|
||||||
|
|
||||||
if (filter != null) {
|
if (filter != null) {
|
||||||
@ -237,9 +237,10 @@ class BiweeklyPresentableCalendar extends AbstractPresentableCalendar {
|
|||||||
*
|
*
|
||||||
* @param frameBegin Begin of the frame where to search events.
|
* @param frameBegin Begin of the frame where to search events.
|
||||||
* @param frameEnd End of the time 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.
|
* @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> positiveEvents = new ArrayList<>();
|
||||||
final List<VEvent> negativeEvents = new ArrayList<>();
|
final List<VEvent> negativeEvents = new ArrayList<>();
|
||||||
classifyEvents(positiveEvents, negativeEvents);
|
classifyEvents(positiveEvents, negativeEvents);
|
||||||
@ -248,6 +249,7 @@ class BiweeklyPresentableCalendar extends AbstractPresentableCalendar {
|
|||||||
for (final VEvent positiveEvent : positiveEvents) {
|
for (final VEvent positiveEvent : positiveEvents) {
|
||||||
final DateIterator positiveBeginDates = getRecurredEventDateIterator(positiveEvent);
|
final DateIterator positiveBeginDates = getRecurredEventDateIterator(positiveEvent);
|
||||||
positiveBeginDates.advanceTo(Date.from(frameBegin));
|
positiveBeginDates.advanceTo(Date.from(frameBegin));
|
||||||
|
int foundInSeries = 0;
|
||||||
while (positiveBeginDates.hasNext()) {
|
while (positiveBeginDates.hasNext()) {
|
||||||
final Instant begInst = positiveBeginDates.next().toInstant();
|
final Instant begInst = positiveBeginDates.next().toInstant();
|
||||||
if (begInst.isAfter(frameEnd)) {
|
if (begInst.isAfter(frameEnd)) {
|
||||||
@ -263,9 +265,17 @@ class BiweeklyPresentableCalendar extends AbstractPresentableCalendar {
|
|||||||
if (eventUid != null) {
|
if (eventUid != null) {
|
||||||
if (!isCounteredBy(begInst, eventUid, negativeEvents)) {
|
if (!isCounteredBy(begInst, eventUid, negativeEvents)) {
|
||||||
eventList.add(resultingVEWP);
|
eventList.add(resultingVEWP);
|
||||||
|
foundInSeries++;
|
||||||
|
if (maximumPerSeries != 0 && foundInSeries >= maximumPerSeries) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
eventList.add(resultingVEWP);
|
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
|
* 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
|
* and checks if these tags are valid
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("null")
|
||||||
@Test
|
@Test
|
||||||
public void testCommandTagCode() {
|
public void testCommandTagCode() {
|
||||||
List<Event> events = null;
|
List<Event> events = null;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user