Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimization of objects number updating #4508

Merged
merged 1 commit into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions core/sockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,10 @@ def sv_set(self, data):
"""Set data, provide context in case the node can be evaluated several times in different context"""
if self.is_output:
data = self.postprocess_output(data)

# it's expensive to call sv_get method to update the number in other places
self.objects_number = len(data)

sv_set_socket(self, data)

def sv_forget(self):
Expand Down Expand Up @@ -548,21 +552,6 @@ def draw_label(text):
def draw_color(self, context, node):
return self.color

def update_objects_number(self): # todo should be the method here?
"""
Should be called each time after process method of the socket owner
It will update number of objects to show in socket labels
"""
try:
self.objects_number = len(self.sv_get(deepcopy=False, default=[]))
except LookupError:
self.objects_number = 0
except Exception as e:
warning(f"Socket='{self.name}' of node='{self.node.name}' can't update number of objects on the label. "
f"Cause is '{e}'")
self.objects_number = 0
raise e


class SvObjectSocket(NodeSocket, SvSocketCommon):
bl_idname = "SvObjectSocket"
Expand Down
5 changes: 0 additions & 5 deletions node_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,6 @@ def update_ui(self, error=None, update_time=None):
else:
sv_bgl.callback_disable(update_pref + self.node_id)

# update object numbers
for s in chain(self.inputs, self.outputs):
if hasattr(s, 'update_objects_number'):
s.update_objects_number()

def insert_link(self, link):
"""It will be triggered only if one socket is connected with another by user"""

Expand Down