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
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:
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)
docs = []
if self.docs is None:
self.docs = docs
for root, dirs, files in os.walk(top):
# Prune dirs
@ -74,8 +76,9 @@ class TaskManager:
path = os.path.join(root, name)
try:
doc = org_rw.load(open(path), extra_cautious=True)
doc = org_rw.load(open(path), extra_cautious=False)
docs.append(doc)
yield doc
except Exception as err:
import traceback
@ -91,7 +94,16 @@ class TaskManager:
def get_task_list(self, callback):
def aux():
if self.docs is None:
self.load()
last_result = None
for doc in self.load():
result = self.get_agenda()
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)