fix(core): prevent duplicate startup logo from nested router lifespan events

FastAPI's merged_lifespan mechanism triggers lifespan events for each
nested router layer. Since program_router is included in v1, which is
included in app, the startup handler was being called 3 times.

Added _startup_done flag to ensure Program.startup() only executes once.

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
Estrella Pan
2026-01-26 07:28:48 +01:00
parent 93d2f2e7d2
commit 12ac30c76a

View File

@@ -30,6 +30,10 @@ figlet = r"""
class Program(RenameThread, RSSThread, OffsetScanThread):
def __init__(self):
super().__init__()
self._startup_done = False
@staticmethod
def __start_info():
for line in figlet.splitlines():
@@ -41,6 +45,10 @@ class Program(RenameThread, RSSThread, OffsetScanThread):
logger.info("Starting AutoBangumi...")
async def startup(self):
# Prevent duplicate startup due to nested router lifespan events
if self._startup_done:
return
self._startup_done = True
self.__start_info()
if not self.database:
first_run()