Skip to content

Commit 37d5ce7

Browse files
authored
Merge pull request #926 from midoks/dev
常规更新
2 parents fb6499c + ef9053a commit 37d5ce7

4 files changed

Lines changed: 29 additions & 4 deletions

File tree

plugins/webstats/index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ def getLogsErrorList():
899899
limit = str(page_size) + ' offset ' + str(page_size * (page - 1))
900900
conn = pSqliteDb('web_logs', domain)
901901

902-
field = 'time,ip,domain,server_name,method,protocol,status_code,ip_list,client_port,body_length,user_agent,referer,request_time,uri,body_length'
902+
field = 'time,scheme,ip,domain,server_name,method,protocol,status_code,ip_list,client_port,body_length,user_agent,referer,request_time,uri,body_length'
903903
conn = conn.field(field)
904904
conn = conn.where("1=1", ())
905905

plugins/webstats/tool_migrate.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,9 @@ def migrateSiteHotLogs(site_name, query_date):
116116
time.sleep(0.5)
117117
copy_start = time.time()
118118
# import shutil
119-
# shutil.copy(hot_db, hot_db_tmp)
120-
mw.fastCopy(hot_db, hot_db_tmp, 256 * 1024)
119+
shutil.copy(hot_db, hot_db_tmp)
120+
# mw.fastCopy(hot_db, hot_db_tmp, 256 * 1024)
121+
# mw.sendfile(hot_db,hot_db_tmp)
121122
print(f"[{site_name}] 备份完成,耗时 {time.time() - copy_start:.2f}s")
122123
if not os.path.exists(hot_db_tmp):
123124
return mw.returnMsg(False, f"{site_name} migrating fail, copy tmp file!")

plugins/webstats/webstats_index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ def getLogsErrorList():
858858
limit = str(page_size) + ' offset ' + str(page_size * (page - 1))
859859
conn = pSqliteDb('web_logs', domain)
860860

861-
field = 'time,ip,domain,server_name,method,protocol,status_code,ip_list,client_port,body_length,user_agent,referer,request_time,uri'
861+
field = 'time,scheme,ip,domain,server_name,method,protocol,status_code,ip_list,client_port,body_length,user_agent,referer,request_time,uri'
862862
conn = conn.field(field)
863863
conn = conn.where("1=1", ())
864864

web/core/mw.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,30 @@ def fastCopy(src, dst, buffer_size=256 * 1024): # 128MB 缓冲区
324324
with open(dst, 'wb') as fdst:
325325
shutil.copyfileobj(fsrc, fdst, length=buffer_size)
326326

327+
328+
# linux高效复制
329+
def sendfile(src, dst):
330+
if isAppleSystem():
331+
try:
332+
shutil.copyfile(src, dst)
333+
return True
334+
except Exception as e:
335+
return False
336+
337+
try:
338+
with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
339+
filesize = os.fstat(fsrc.fileno()).st_size
340+
sent = os.sendfile(fdst.fileno(), fsrc.fileno(), 0, filesize)
341+
if sent != filesize:
342+
shutil.copyfile(src, dst)
343+
return True
344+
except (OSError, AttributeError) as e:
345+
try:
346+
shutil.copyfile(src, dst)
347+
return True
348+
except Exception as e2:
349+
return False
350+
327351
def returnData(status, msg, data=None):
328352
if data is None:
329353
return {'status': status, 'msg': msg}

0 commit comments

Comments
 (0)