Skip to content

Commit

Permalink
Improve performance by reducing retrieved data
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerSelwyn committed Apr 2, 2023
1 parent c2d0a83 commit 822c7ab
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
16 changes: 15 additions & 1 deletion custom_components/o365/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,21 @@ async def _async_calendar_schedule_get_events(
self, hass, calendar_schedule, start_date, end_date
):
"""Get the events for the calendar."""
query = calendar_schedule.new_query("start").greater_equal(start_date)
query = calendar_schedule.new_query()
query = query.select(
"subject",
"body",
"start",
"end",
"is_all_day",
"location",
"categories",
"sensitivity",
"show_as",
"attendees",
"series_master_id",
)
query = query.on_attribute("start").greater_equal(start_date)
query.chain("and").on_attribute("end").less_equal(end_date)
if self._search is not None:
query.chain("and").on_attribute("subject").contains(self._search)
Expand Down
21 changes: 17 additions & 4 deletions custom_components/o365/classes/mailsensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,23 @@ def __init__(
self.download_attachments = sensor_conf.get(CONF_DOWNLOAD_ATTACHMENTS)
self.html_body = sensor_conf.get(CONF_HTML_BODY)
self.max_items = sensor_conf.get(CONF_MAX_ITEMS, 5)
self.query = None
self.query = self.mail_folder.new_query()
self.query = self.query.select(
"sender",
"from",
"subject",
"body",
"receivedDateTime",
"toRecipients",
"ccRecipients",
"has_attachments",
"importance",
"is_read",
)
if self.download_attachments:
self.query = self.query.select(
"attachments",
)
self._config = config

@property
Expand All @@ -78,7 +94,6 @@ def __init__(
coordinator, config, sensor_conf, mail_folder, name, entity_id, unique_id
)

self.query = self.mail_folder.new_query()
self.query.order_by("receivedDateTime", ascending=False)

self._build_query(sensor_conf)
Expand Down Expand Up @@ -138,9 +153,7 @@ def __init__(

is_unread = sensor_conf.get(CONF_IS_UNREAD)

self.query = None
if is_unread is not None:
self.query = self.mail_folder.new_query()
self.query.chain("and").on_attribute("IsRead").equals(not is_unread)


Expand Down

0 comments on commit 822c7ab

Please sign in to comment.