Skip to content

Commit 10a085e

Browse files
committed
perf: introduce caching
1 parent 7f9bf67 commit 10a085e

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

beet_observer/plugin.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@
77
def beet_default(ctx: Context):
88
if "observer" not in ctx.meta:
99
return
10+
11+
# # check cache
12+
cache = ctx.cache["observer"]
13+
cached_dp = False
14+
cached_rp = False
15+
dp_path = None
16+
rp_path = None
17+
if ctx.data:
18+
dp_path = cache.get_path(f"{ctx.directory} saved_data_pack")
19+
if dp_path.is_dir():
20+
ctx.data.load(f"{dp_path}")
21+
cached_dp = True
22+
if ctx.assets:
23+
rp_path = cache.get_path(f"{ctx.directory} saved_resource_pack")
24+
if rp_path.is_dir():
25+
ctx.assets.load(f"{rp_path}")
26+
cached_rp = True
27+
if cached_dp and cached_rp:
28+
return
29+
1030
# get default directories
1131
if "default_dir" not in ctx.meta["observer"]:
1232
# default dir not defined
@@ -46,5 +66,13 @@ def beet_default(ctx: Context):
4666
dp_dir = overlay["directory"]
4767
rp_dir = overlay["directory"]
4868
# compare build pack and overlay pack
49-
gen_dp_overlays(ctx, ctx_overlay, dp_dir, save)
50-
gen_rp_overlays(ctx, ctx_overlay, rp_dir, save)
69+
if not cached_dp and ctx.data:
70+
gen_dp_overlays(ctx, ctx_overlay, dp_dir, save)
71+
if not cached_rp and ctx.assets:
72+
gen_rp_overlays(ctx, ctx_overlay, rp_dir, save)
73+
74+
# save to cache
75+
if not cached_dp and ctx.data:
76+
ctx.data.save(path=dp_path)
77+
if not cached_rp and ctx.assets:
78+
ctx.assets.save(path=rp_path)

0 commit comments

Comments
 (0)