利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.
Python ai-video-generatorcontent-creationffmpeginstagram-reelsllmpythonshort-videosubtitlestext-to-speechtiktokvideo-automationvideo-workflowworkflow-automationyoutube-shorts
perf(state): copy only requested memory task page
Rudy Celekliee3f7afaf93c
diff --git a/app/services/state.py b/app/services/state.pyindex 7ee25c22..7b629593 100644--- a/app/services/state.py+++ b/app/services/state.py@@ -2,6 +2,7 @@ import astimport copyimport threadingfrom abc import ABC, abstractmethod+from itertools import islicefrom app.config import configfrom app.models import const@@ -55,9 +56,12 @@ class MemoryState(BaseState):start = (page - 1) * page_sizeend = start + page_sizewith self._lock:- tasks = [copy.deepcopy(task) for task in self._tasks.values()]- total = len(tasks)- return tasks[start:end], total+ total = len(self._tasks)+ tasks = [+ copy.deepcopy(task)+ for task in islice(self._tasks.values(), start, end)+ ]+ return tasks, totaldef list_task_ids(self, scan_count: int = 100) -> list[str]:with self._lock:diff --git a/test/services/test_state.py b/test/services/test_state.pyindex 67f8c935..b8daa4e2 100644--- a/test/services/test_state.py+++ b/test/services/test_state.py@@ -129,6 +129,32 @@ class TestMemoryState(unittest.TestCase):self.assertEqual(total, 1)self.assertEqual(state.get_task("task-1")["videos"], ["first.mp4"])+ def test_get_all_tasks_copies_only_the_requested_page(self):+ """A small page should not clone every historical task payload."""++ class CopyTracked:+ def __init__(self):+ self.copies = 0++ def __deepcopy__(self, memo):+ self.copies += 1+ return CopyTracked()++ state = MemoryState()+ off_page = CopyTracked()+ state.update_task("task-1", videos=["first.mp4"])+ state.update_task("task-2", payload=off_page)++ first_page, total = state.get_all_tasks(page=1, page_size=1)++ self.assertEqual(total, 2)+ self.assertEqual([task["task_id"] for task in first_page], ["task-1"])+ self.assertEqual(off_page.copies, 0)++ second_page, _ = state.get_all_tasks(page=2, page_size=1)+ self.assertEqual([task["task_id"] for task in second_page], ["task-2"])+ self.assertEqual(off_page.copies, 1)+def test_concurrent_memory_updates_are_preserved(self):state = MemoryState()thread_count = 5