Skip to content

Commit

Permalink
caching and layout reloading
Browse files Browse the repository at this point in the history
  • Loading branch information
ilude committed Apr 18, 2024
1 parent 889bcbb commit 0a422a7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
6 changes: 3 additions & 3 deletions app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import signal
import sys
from datetime import datetime
from typing import Any
from flask import Flask, render_template
from flask_assets import Environment, Bundle
from flask_caching import Cache

from typing import Any
from utils import copy_default_to_configs

copy_default_to_configs()
Expand Down Expand Up @@ -56,7 +55,8 @@ def inject_current_date():
@cache.cached(timeout=page_timeout, unless=lambda: layout.is_modified)
def index(tab_name=None):
# Load feeds and bookmarks
layout.reload()
if layout.is_modified():
layout.reload()

return render_template('index.html', layout=layout, tab_name=tab_name, skip_htmx=False)

Expand Down
19 changes: 14 additions & 5 deletions app/models/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,35 @@
import yaml
from models.utils import from_list

logger = logging.getLogger(__name__)

class Layout:
headers: list['Bookmark'] = []
tabs: list['Tab'] = []

def __init__(self, config_file: str = "configs/layout.yml"):
logger.setLevel(logging.DEBUG)
self.config_path = pwd.joinpath(config_file)
self.reload()


def stop_scheduler(self):
scheduler = SchedulerWidget.getScheduler()
if scheduler and scheduler.running:
scheduler.shutdown()


def is_modified(self):
return self.mtime > self.last_reload
modified = self.mtime > self.last_reload
logger.debug(f"Layout modified: {modified} mtime: {self.mtime} last_reload: {self.last_reload}")
return modified


@property
def mtime(self):
return os.path.getmtime(self.config_path)


def reload(self):
from models.tab import Tab
from models.Bookmark import Bookmark
Expand All @@ -40,10 +52,6 @@ def reload(self):
logging.debug("Layout reloaded!")


@property
def mtime(self):
return os.path.getmtime(self.config_path)


def tab(self, name: str) -> 'Tab':
if name is None:
Expand Down Expand Up @@ -78,5 +86,6 @@ def get_feed(self, feed_id: str) -> 'Feed':
self.feed_hash[feed.id] = feed

return self.feed_hash[feed_id]


layout = Layout()

0 comments on commit 0a422a7

Please sign in to comment.