Skip to content

Commit

Permalink
fix: 数据库写入失败
Browse files Browse the repository at this point in the history
  • Loading branch information
linyuan0213 committed Jul 10, 2024
1 parent 8499a66 commit dbd3694
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 32 deletions.
50 changes: 27 additions & 23 deletions app/indexer/client/_base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
from threading import Lock
import xml.dom.minidom
from abc import ABCMeta, abstractmethod

Expand All @@ -23,6 +24,7 @@ class _IIndexClient(metaclass=ABCMeta):
progress = None
filter = None
dbhelper = None
lock = Lock()

def __init__(self):
self.media = Media()
Expand Down Expand Up @@ -95,31 +97,33 @@ def search(self, order_seq,
# 索引花费时间
seconds = (datetime.datetime.now() - start_time).seconds
if len(result_array) == 0:
log.warn(f"【{self.index_type}{indexer.name} 关键词 {key_word} 未搜索到数据")
self.progress.update(ptype=ProgressKey.Search, text=f"{indexer.name} 关键词 {key_word} 未搜索到数据")
with self.lock:
log.warn(f"【{self.index_type}{indexer.name} 关键词 {key_word} 未搜索到数据")
self.progress.update(ptype=ProgressKey.Search, text=f"{indexer.name} 关键词 {key_word} 未搜索到数据")

self.dbhelper.insert_indexer_statistics(indexer=indexer.name,
itype=self.client_id,
seconds=seconds,
result='N'
)
return []
self.dbhelper.insert_indexer_statistics(indexer=indexer.name,
itype=self.client_id,
seconds=seconds,
result='N'
)
return []
else:
log.warn(f"【{self.index_type}{indexer.name} 关键词 {key_word} 返回数据:{len(result_array)}")
# 更新进度
self.progress.update(ptype=ProgressKey.Search, text=f"{indexer.name} 关键词 {key_word} 返回 {len(result_array)} 条数据")
# 索引统计
self.dbhelper.insert_indexer_statistics(indexer=indexer.name,
itype=self.client_id,
seconds=seconds,
result='Y'
)
return self.filter_search_results(result_array=result_array,
order_seq=order_seq,
indexer=indexer,
filter_args=filter_args,
match_media=match_media,
start_time=start_time)
with self.lock:
log.warn(f"【{self.index_type}{indexer.name} 关键词 {key_word} 返回数据:{len(result_array)}")
# 更新进度
self.progress.update(ptype=ProgressKey.Search, text=f"{indexer.name} 关键词 {key_word} 返回 {len(result_array)} 条数据")
# 索引统计
self.dbhelper.insert_indexer_statistics(indexer=indexer.name,
itype=self.client_id,
seconds=seconds,
result='Y'
)
return self.filter_search_results(result_array=result_array,
order_seq=order_seq,
indexer=indexer,
filter_args=filter_args,
match_media=match_media,
start_time=start_time)

@staticmethod
def __parse_torznabxml(url):
Expand Down
22 changes: 13 additions & 9 deletions app/indexer/client/builtin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import copy
import datetime
from threading import Lock
import time

from app.helper.drissionpage_helper import DrissionPageHelper
Expand Down Expand Up @@ -35,6 +36,7 @@ class BuiltinIndexer(_IIndexClient):
progress = None
sites = None
dbhelper = None
lock = Lock()

def __init__(self, config=None):
super().__init__()
Expand Down Expand Up @@ -182,11 +184,12 @@ def search(self, order_seq,
# 索引花费的时间
seconds = round((datetime.datetime.now() - start_time).seconds, 1)
# 索引统计
self.dbhelper.insert_indexer_statistics(indexer=indexer.name,
itype=self.client_id,
seconds=seconds,
result='N' if error_flag else 'Y')
# 返回结果
with self.lock:
self.dbhelper.insert_indexer_statistics(indexer=indexer.name,
itype=self.client_id,
seconds=seconds,
result='N' if error_flag else 'Y')
# 返回结果
if len(result_array) == 0:
log.warn(f"【{self.client_name}{indexer.name} 关键词 {key_word} 未搜索到数据")
# 更新进度
Expand Down Expand Up @@ -240,10 +243,11 @@ def list(self, index_id, page=0, keyword=None):
seconds = round((datetime.datetime.now() - start_time).seconds, 1)

# 索引统计
self.dbhelper.insert_indexer_statistics(indexer=indexer.name,
itype=self.client_id,
seconds=seconds,
result='N' if error_flag else 'Y')
with self.lock:
self.dbhelper.insert_indexer_statistics(indexer=indexer.name,
itype=self.client_id,
seconds=seconds,
result='N' if error_flag else 'Y')
return result_array

@staticmethod
Expand Down

0 comments on commit dbd3694

Please sign in to comment.