Skip to content

Commit

Permalink
refactor(watcher): optimization: we only care about file events
Browse files Browse the repository at this point in the history
  • Loading branch information
dairiki committed Mar 10, 2023
1 parent f7c6b26 commit 1d790bb
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lektor/watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,21 @@ def __init__(self):
super().__init__()
self.queue = queue.Queue()

# Generally we only care about changes (modification, creation, deletion) to files
# within the monitored tree. Changes in directories do not directly affect Lektor
# output. So, in general, we ignore directory events.
#
# However, the "efficient" (i.e. non-polling) observers do not seem to generate
# events for files contained in directories that are moved out of the watched tree.
# The only events generated in that case are for the directory — generally a
# DirDeletedEvent is generated — so we can't ignore those.
#
# (Moving/renaming a directory does not seem to reliably generate a DirMovedEvent,
# but we might as well track those, too.)

def on_created(self, event):
self.queue.put((time.time(), event.event_type, event.src_path))
if not event.is_directory:
self.queue.put((time.time(), event.event_type, event.src_path))

def on_deleted(self, event):
self.queue.put((time.time(), event.event_type, event.src_path))
Expand Down

0 comments on commit 1d790bb

Please sign in to comment.