From a691774afd0420bab4f8220fe05d2077724be4bd Mon Sep 17 00:00:00 2001 From: yumoqing Date: Tue, 26 May 2026 09:27:52 +0800 Subject: [PATCH] fix: optimize isHtml() to read only first 512 bytes instead of entire file Changed from reading full file content to reading first 512 bytes in binary mode, significantly improving static file serving performance for large files like echarts.min.js (1MB+). Before: async with aiofiles.open(fn,'r',encoding='utf-8') as f: b = await f.read() After: async with aiofiles.open(fn,'rb') as f: b = await f.read(512) --- ahserver/processorResource.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ahserver/processorResource.py b/ahserver/processorResource.py index 2751b67..9e9a7bf 100644 --- a/ahserver/processorResource.py +++ b/ahserver/processorResource.py @@ -397,8 +397,9 @@ class ProcessorResource(StaticResource,Url2File): async def isHtml(self,fn): try: - async with aiofiles.open(fn,'r',encoding='utf-8') as f: - b = await f.read() + async with aiofiles.open(fn,'rb') as f: + b = await f.read(512) + b = b.decode('utf-8', errors='ignore') while b[0] in ['\n',' ','\t']: b = b[1:] if b.lower().startswith(''):