Draft naive incremental load.

This commit is contained in:
Sergio Martínez Portela 2022-03-25 19:26:53 +01:00
parent 68a2cd9b11
commit 35c46ba894
2 changed files with 26 additions and 5 deletions

View File

@ -95,6 +95,15 @@ class MainWindow(Gtk.Window):
## Callbacks ## Callbacks
def on_task_list_ready(self, agenda): def on_task_list_ready(self, agenda):
# TODO: Avoid reconstructing the whole list every time
i = 0
child = self.task_list.get_first_child()
while child is not None:
was = child
child = child.get_next_sibling()
i += 1
self.task_list.remove(was)
for item in agenda.with_hour: for item in agenda.with_hour:
self.task_list.append(self.build_agenda_task_row(item)) self.task_list.append(self.build_agenda_task_row(item))

View File

@ -56,6 +56,8 @@ class TaskManager:
top = os.path.abspath(self.docs_path) top = os.path.abspath(self.docs_path)
docs = [] docs = []
if self.docs is None:
self.docs = docs
for root, dirs, files in os.walk(top): for root, dirs, files in os.walk(top):
# Prune dirs # Prune dirs
@ -74,8 +76,9 @@ class TaskManager:
path = os.path.join(root, name) path = os.path.join(root, name)
try: try:
doc = org_rw.load(open(path), extra_cautious=True) doc = org_rw.load(open(path), extra_cautious=False)
docs.append(doc) docs.append(doc)
yield doc
except Exception as err: except Exception as err:
import traceback import traceback
@ -91,10 +94,19 @@ class TaskManager:
def get_task_list(self, callback): def get_task_list(self, callback):
def aux(): def aux():
if self.docs is None: if self.docs is None:
self.load() last_result = None
result = self.get_agenda() for doc in self.load():
print("Result", result) result = self.get_agenda()
GObject.idle_add(callback, result) if ((last_result is None)
or (len(result.with_hour) != len(last_result.with_hour))
or (len(result.no_hour) != len(last_result.no_hour))):
print("Loaded:", doc._path)
GObject.idle_add(callback, result)
print("Load completed")
else:
result = self.get_agenda()
print("Result", result)
GObject.idle_add(callback, result)
thread = threading.Thread(target=aux) thread = threading.Thread(target=aux)
thread.start() thread.start()