Skip to content

Commit

Permalink
优化:图片组件清理缓存前的检查
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroi-sora committed Jan 15, 2024
1 parent de1bb6e commit dbe5618
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions UmiOCR-data/py_src/image_controller/image_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self):
def requestPixmap(self, path, size=None, resSize=None):
if "/" in path:
compID, imgID = path.split("/", 1)
self._delCompCache(compID) # 先清缓存
self._delCompCache(compID, imgID) # 先清缓存
if imgID in self.pixmapDict:
self.compDict[compID] = imgID # 记录缓存
return self.pixmapDict[imgID]
Expand Down Expand Up @@ -100,10 +100,13 @@ def toBytes(image):
bytesData = byteArray.data() # 获取字节数组的内容
return bytesData

# 清空一个组件的缓存
def _delCompCache(self, compID):
# 清空一个组件的缓存。imgID可选该组件下一次更新的图片ID。
def _delCompCache(self, compID, imgID=""):
if compID in self.compDict:
last = self.compDict[compID]
if imgID and imgID == last:
print(f"[Warning] 图片组件异常清理: {compID} {imgID}")
return # 如果下一次更新的ID等于当前ID,则为异常,不进行清理
if last in self.pixmapDict:
del self.pixmapDict[last]
del self.compDict[compID]
Expand Down

0 comments on commit dbe5618

Please sign in to comment.