Skip to content

Commit

Permalink
Cache fqdn to speed up processing
Browse files Browse the repository at this point in the history
  • Loading branch information
jspricke committed Jul 16, 2022
1 parent 8582ef6 commit 12a82f0
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions remind.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __init__(
startdate: date = None,
month: int = 15,
alarm: timedelta = None,
fqdn: str = None,
) -> None:
"""Constructor.
Expand All @@ -61,6 +62,7 @@ def __init__(
self._lock = Lock()
self._reminders: dict[str, dict[str, Any]] = {}
self._mtime = 0.0
self._fqdn = fqdn if fqdn else getfqdn()

def _parse_remind(
self, filename: str, lines: str = ""
Expand Down Expand Up @@ -124,7 +126,7 @@ def _parse_remind(
else:
continue

entry["uid"] = f"{entry['tags'].split(',')[-1][7:]}@{getfqdn()}"
entry["uid"] = f"{entry['tags'].split(',')[-1][7:]}@{self._fqdn}"

if "eventstart" in entry:
dtstart: datetime | date = datetime.strptime(
Expand Down Expand Up @@ -279,10 +281,9 @@ def get_filesnames(self) -> list[str]:
self._update()
return list(self._reminders.keys())

@staticmethod
def _get_uid(line: str) -> str:
def _get_uid(self, line: str) -> str:
"""UID of a remind line."""
return f"{md5(line.strip().encode('utf-8')).hexdigest()}@{getfqdn()}"
return f"{md5(line.strip().encode('utf-8')).hexdigest()}@{self._fqdn}"

def get_uids(self, filename: str = "") -> list[str]:
"""UIDs of all reminders in the file excluding included files.
Expand Down Expand Up @@ -606,7 +607,7 @@ def append_vobject(self, ical: Component, filename: str = "") -> str:
with open(filename, "a", encoding="utf-8") as outfile:
outfile.write(outdat)

return Remind._get_uid(outdat)
return self._get_uid(outdat)

def remove(self, uid: str, filename: str = "") -> None:
"""Remove the Remind command with the uid from the file."""
Expand Down

0 comments on commit 12a82f0

Please sign in to comment.