This commit is contained in:
Timothy Jaeryang Baek 2025-05-27 16:06:00 +04:00
parent 8609471eeb
commit 40bea00e3d
2 changed files with 40 additions and 23 deletions

View File

@ -66,7 +66,9 @@ async def process_filter_functions(
if not filter:
continue
function_module = get_function_module(request, filter_id)
function_module = get_function_module(
request, filter_id, load_from_db=(filter_type != "stream")
)
# Prepare handler function
handler = getattr(function_module, filter_type, None)
if not handler:

View File

@ -166,7 +166,10 @@ def load_function_module_by_id(function_id: str, content: str | None = None):
os.unlink(temp_file.name)
def get_function_module_from_cache(request, function_id):
def get_function_module_from_cache(request, function_id, load_from_db=True):
if load_from_db:
# Always load from the database if requested
function = Functions.get_function_by_id(function_id)
if not function:
raise Exception(f"Function not found: {function_id}")
@ -191,6 +194,18 @@ def get_function_module_from_cache(request, function_id):
function_module, function_type, frontmatter = load_function_module_by_id(
function_id, content
)
else:
# Load from cache (e.g. "stream" hook)
if (
hasattr(request.app.state, "FUNCTIONS")
and function_id in request.app.state.FUNCTIONS
):
if request.app.state.FUNCTION_CONTENTS[function_id] == content:
return request.app.state.FUNCTIONS[function_id], None, None
function_module, function_type, frontmatter = load_function_module_by_id(
function_id
)
if not hasattr(request.app.state, "FUNCTIONS"):
request.app.state.FUNCTIONS = {}