summaryrefslogtreecommitdiff
path: root/lib/elements
diff options
context:
space:
mode:
authorKaalleen <36401965+kaalleen@users.noreply.github.com>2023-02-25 09:31:40 +0100
committerGitHub <noreply@github.com>2023-02-25 09:31:40 +0100
commited0ab5a44d08068e9f02bc689edc03899995e74b (patch)
treeaf17ada374e2ab18d38bb62fe1a51024aa795910 /lib/elements
parent2cb1782fd31ba287ec21c22194e0b3bfa87aa2a1 (diff)
Clone Cache (#2086)
Co-authored-by: Lex Neva
Diffstat (limited to 'lib/elements')
-rw-r--r--lib/elements/clone.py5
-rw-r--r--lib/elements/element.py12
2 files changed, 13 insertions, 4 deletions
diff --git a/lib/elements/clone.py b/lib/elements/clone.py
index b5507e4f..5100def1 100644
--- a/lib/elements/clone.py
+++ b/lib/elements/clone.py
@@ -72,6 +72,11 @@ class Clone(EmbroideryElement):
def flip_angle(self):
return self.get_boolean_param('flip_angle')
+ def get_cache_key_data(self, previous_stitch):
+ source_node = get_clone_source(self.node)
+ source_elements = self.clone_to_element(source_node)
+ return [element.get_cache_key(previous_stitch) for element in source_elements]
+
def clone_to_element(self, node):
from .utils import node_to_elements
return node_to_elements(node, True)
diff --git a/lib/elements/element.py b/lib/elements/element.py
index 5e8bb072..3a9f331c 100644
--- a/lib/elements/element.py
+++ b/lib/elements/element.py
@@ -397,7 +397,7 @@ class EmbroideryElement(object):
# we don't care about the previous stitch
previous_stitch = None
- cache_key = self._get_cache_key(previous_stitch)
+ cache_key = self.get_cache_key(previous_stitch)
stitch_groups = get_stitch_plan_cache().get(cache_key)
if stitch_groups:
@@ -417,14 +417,14 @@ class EmbroideryElement(object):
@debug.time
def _save_cached_stitch_groups(self, stitch_groups, previous_stitch):
stitch_plan_cache = get_stitch_plan_cache()
- cache_key = self._get_cache_key(previous_stitch)
+ cache_key = self.get_cache_key(previous_stitch)
if cache_key not in stitch_plan_cache:
stitch_plan_cache[cache_key] = stitch_groups
if previous_stitch is not None:
# Also store it with None as the previous stitch, so that it can be used next time
# if we don't care about the previous stitch
- cache_key = self._get_cache_key(None)
+ cache_key = self.get_cache_key(None)
if cache_key not in stitch_plan_cache:
stitch_plan_cache[cache_key] = stitch_groups
@@ -443,7 +443,10 @@ class EmbroideryElement(object):
def _get_guides_cache_key_data(self):
return get_marker_elements_cache_key_data(self.node, "guide-line")
- def _get_cache_key(self, previous_stitch):
+ def get_cache_key_data(self, previous_stitch):
+ return []
+
+ def get_cache_key(self, previous_stitch):
cache_key_generator = CacheKeyGenerator()
cache_key_generator.update(self.__class__.__name__)
cache_key_generator.update(self.get_params_and_values())
@@ -453,6 +456,7 @@ class EmbroideryElement(object):
cache_key_generator.update([(c.command, c.target_point) for c in self.commands])
cache_key_generator.update(self._get_patterns_cache_key_data())
cache_key_generator.update(self._get_guides_cache_key_data())
+ cache_key_generator.update(self.get_cache_key_data(previous_stitch))
cache_key = cache_key_generator.get_cache_key()
debug.log(f"cache key for {self.node.get('id')} {self.node.get(INKSCAPE_LABEL)} {previous_stitch}: {cache_key}")