Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Overbill1683
Stable Diffusion Webui
提交
52620763
S
Stable Diffusion Webui
项目概览
Overbill1683
/
Stable Diffusion Webui
9 个月 前同步成功
通知
1732
Star
80
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
分析
仓库
DevOps
项目成员
Pages
S
Stable Diffusion Webui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
52620763
编写于
8月 31, 2023
作者:
W
w-e-w
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
clean up message spam
上级
8fc0f5d2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
18 addition
and
12 deletion
+18
-12
modules/cache.py
modules/cache.py
+17
-11
modules/hashes.py
modules/hashes.py
+1
-1
未找到文件。
modules/cache.py
浏览文件 @
52620763
...
...
@@ -19,13 +19,14 @@ dump_cache_thread = None
def
cache_db_to_dict
(
db_path
):
try
:
database_dict
=
{}
with
sqlite3
.
connect
(
db_path
)
as
conn
:
database_dict
=
{}
for
table
in
conn
.
execute
(
"SELECT name FROM sqlite_master WHERE type='table'"
).
fetchall
():
table_name
=
table
[
0
]
table_data
=
conn
.
execute
(
f
"SELECT * FROM `
{
table_name
}
`"
).
fetchall
()
database_dict
[
table_name
]
=
{
row
[
0
]:
{
"mtime"
:
row
[
1
],
"value"
:
json
.
loads
(
row
[
2
])}
for
row
in
table_data
}
return
database_dict
database_dict
[
table_name
]
=
{
row
[
0
]:
{
"mtime"
:
row
[
1
],
"value"
:
json
.
loads
(
row
[
2
])}
for
row
in
table_data
}
return
database_dict
except
Exception
as
e
:
print
(
e
)
return
{}
...
...
@@ -84,8 +85,10 @@ def cache(subsection):
s
=
cache_data
.
get
(
subsection
,
{})
if
not
s
:
try
:
with
sqlite3
.
connect
(
cache_db_path
)
as
conn
:
conn
.
execute
(
f
'CREATE TABLE IF NOT EXISTS `
{
subsection
}
` (path TEXT PRIMARY KEY, mtime REAL, value TEXT)'
)
with
cache_lock
:
with
sqlite3
.
connect
(
cache_db_path
)
as
conn
:
conn
.
execute
(
f
'CREATE TABLE IF NOT EXISTS `
{
subsection
}
` (path TEXT PRIMARY KEY, mtime REAL, value TEXT)'
)
except
Exception
as
e
:
print
(
e
)
cache_data
[
subsection
]
=
s
...
...
@@ -102,7 +105,8 @@ def cache(subsection):
cache_data
=
json
.
load
(
file
)
except
Exception
:
os
.
replace
(
cache_filename
,
os
.
path
.
join
(
script_path
,
"tmp"
,
"cache.json"
))
print
(
'[ERROR] issue occurred while trying to read cache.json, move current cache to tmp/cache.json and create new cache'
)
print
(
'[ERROR] issue occurred while trying to read cache.json, move current cache to tmp/cache.json and create new cache'
)
cache_data
=
{}
s
=
cache_data
.
get
(
subsection
,
{})
...
...
@@ -111,7 +115,7 @@ def cache(subsection):
return
s
def
cached_data_for_file
(
subsection
,
title
,
filename
,
func
):
def
cached_data_for_file
(
subsection
,
title
,
filename
,
func
,
func_message
:
str
=
None
):
"""
Retrieves or generates data for a specific file, using a caching mechanism.
...
...
@@ -120,7 +124,7 @@ def cached_data_for_file(subsection, title, filename, func):
title (str): The title of the data entry in the subsection of the cache.
filename (str): The path to the file to be checked for modifications.
func (callable): A function that generates the data if it is not available in the cache.
func_message (str): when non-blank, prints {func_message}{func()} if func is called
Returns:
dict or None: The cached or generated data, or None if data generation fails.
...
...
@@ -144,7 +148,11 @@ def cached_data_for_file(subsection, title, filename, func):
entry
=
None
if
not
entry
or
'value'
not
in
entry
:
if
func_message
:
print
(
f
"
{
func_message
}
"
,
end
=
""
)
value
=
func
()
if
func_message
:
print
(
value
)
if
value
is
None
:
return
None
...
...
@@ -154,10 +162,8 @@ def cached_data_for_file(subsection, title, filename, func):
with
sqlite3
.
connect
(
cache_db_path
)
as
conn
:
insert_or_replace
=
f
"INSERT OR REPLACE INTO `
{
subsection
}
` (path, mtime, value) VALUES (?, ?, ?)"
conn
.
execute
(
insert_or_replace
,
(
title
,
ondisk_mtime
,
json
.
dumps
(
value
)))
existing_cache
=
cache
(
subsection
)
existing_cache
[
title
]
=
{
'mtime'
:
ondisk_mtime
,
'value'
:
value
}
print
(
f
'
{
title
}
:
{
value
}
'
)
return
value
return
value
except
Exception
as
e
:
print
(
e
)
return
None
...
...
modules/hashes.py
浏览文件 @
52620763
...
...
@@ -44,7 +44,7 @@ def sha256(filename, title, use_addnet_hash=False):
else
:
subsection
=
"hashes"
calculate_hash
=
partial
(
calculate_sha256
,
filename
)
return
modules
.
cache
.
cached_data_for_file
(
subsection
,
title
,
filename
,
calculate_hash
)
return
modules
.
cache
.
cached_data_for_file
(
subsection
,
title
,
filename
,
calculate_hash
,
f
"Calculating sha256 for
{
filename
}
: "
)
hashes
=
cache
(
"hashes-addnet"
)
if
use_addnet_hash
else
cache
(
"hashes"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录