home · contact · privacy
Overhaul caching.
[plomtask] / plomtask / http.py
index 91db32601c24c91c49db75df4f9ca2b05fd9b944..fc0059c530e20c5e347a264703905b3fcadcb3df 100644 (file)
@@ -139,8 +139,11 @@ class TaskHandler(BaseHTTPRequestHandler):
                         msg = f'{not_found_msg}: {self._site}'
                         raise NotFoundException(msg)
                 except HandledException as error:
-                    html = self.server.jinja.\
-                            get_template('msg.html').render(msg=error)
+                    for cls in (Day, Todo, Condition, Process, ProcessStep):
+                        assert hasattr(cls, 'empty_cache')
+                        cls.empty_cache()
+                    tmpl = self.server.jinja.get_template('msg.html')
+                    html = tmpl.render(msg=error)
                     self._send_html(html, error.http_code)
                 finally:
                     self.conn.close()
@@ -205,12 +208,12 @@ class TaskHandler(BaseHTTPRequestHandler):
     def do_GET_day(self) -> dict[str, object]:
         """Show single Day of ?date=."""
         date = self._params.get_str('date', date_in_n_days(0))
+        day = Day.by_id(self.conn, date, create=True)
         make_type = self._params.get_str('make_type')
-        todays_todos = Todo.by_date(self.conn, date)
         conditions_present = []
         enablers_for = {}
         disablers_for = {}
-        for todo in todays_todos:
+        for todo in day.todos:
             for condition in todo.conditions + todo.blockers:
                 if condition not in conditions_present:
                     conditions_present += [condition]
@@ -222,9 +225,8 @@ class TaskHandler(BaseHTTPRequestHandler):
                                                     if condition in p.disables]
         seen_todos: set[int] = set()
         top_nodes = [t.get_step_tree(seen_todos)
-                     for t in todays_todos if not t.parents]
-        return {'day': Day.by_id(self.conn, date, create=True),
-                'total_effort': Todo.total_effort_at_date(self.conn, date),
+                     for t in day.todos if not t.parents]
+        return {'day': day,
                 'top_nodes': top_nodes,
                 'make_type': make_type,
                 'enablers_for': enablers_for,
@@ -482,10 +484,6 @@ class TaskHandler(BaseHTTPRequestHandler):
             if len(efforts) > 0:
                 todo.effort = float(efforts[i]) if efforts[i] else None
             todo.save(self.conn)
-            for condition in todo.enables:
-                condition.save(self.conn)
-            for condition in todo.disables:
-                condition.save(self.conn)
         return f'/day?date={date}&make_type={make_type}'
 
     def do_POST_todo(self) -> str:
@@ -541,10 +539,6 @@ class TaskHandler(BaseHTTPRequestHandler):
         todo.calendarize = len(self._form_data.get_all_str('calendarize')) > 0
         todo.comment = self._form_data.get_str('comment', ignore_strict=True)
         todo.save(self.conn)
-        for condition in todo.enables:
-            condition.save(self.conn)
-        for condition in todo.disables:
-            condition.save(self.conn)
         return f'/todo?id={todo.id_}'
 
     def do_POST_process_descriptions(self) -> str:
@@ -606,12 +600,10 @@ class TaskHandler(BaseHTTPRequestHandler):
                                       None)]
             except ValueError:
                 new_step_title = step_identifier
-        process.uncache()
         process.set_steps(self.conn, steps)
         process.set_step_suppressions(self.conn,
                                       self._form_data.
                                       get_all_int('suppresses'))
-        process.save(self.conn)
         owners_to_set = []
         new_owner_title = None
         for owner_identifier in self._form_data.get_all_str('step_of'):
@@ -627,6 +619,7 @@ class TaskHandler(BaseHTTPRequestHandler):
         elif new_owner_title:
             title_b64_encoded = b64encode(new_owner_title.encode()).decode()
             params = f'has_step={process.id_}&title_b64={title_b64_encoded}'
+        process.save(self.conn)
         return f'/process?{params}'
 
     def do_POST_condition_descriptions(self) -> str: