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)
This commit is contained in:
parent
f0bf17a72c
commit
a691774afd
@ -397,8 +397,9 @@ class ProcessorResource(StaticResource,Url2File):
|
|||||||
|
|
||||||
async def isHtml(self,fn):
|
async def isHtml(self,fn):
|
||||||
try:
|
try:
|
||||||
async with aiofiles.open(fn,'r',encoding='utf-8') as f:
|
async with aiofiles.open(fn,'rb') as f:
|
||||||
b = await f.read()
|
b = await f.read(512)
|
||||||
|
b = b.decode('utf-8', errors='ignore')
|
||||||
while b[0] in ['\n',' ','\t']:
|
while b[0] in ['\n',' ','\t']:
|
||||||
b = b[1:]
|
b = b[1:]
|
||||||
if b.lower().startswith('<html>'):
|
if b.lower().startswith('<html>'):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user