Sync: upload caching fix
A POST to create a new node didn't invalidate the preceeding GET on /nodes to find whether the node already exists. As a result, the negative answer was cached, and new nodes were created even though the node already existed.
This commit is contained in:
parent
332c32ca9c
commit
af53d61cf2
@ -197,7 +197,7 @@ class PILLAR_OT_sync(async_loop.AsyncModalOperatorMixin, bpy.types.Operator):
|
|||||||
sync_group = await pillar_call(pillarsdk.Node.find_first, {
|
sync_group = await pillar_call(pillarsdk.Node.find_first, {
|
||||||
'where': node_props,
|
'where': node_props,
|
||||||
'projection': {'_id': 1}
|
'projection': {'_id': 1}
|
||||||
})
|
}, caching=False)
|
||||||
|
|
||||||
if sync_group is None:
|
if sync_group is None:
|
||||||
log.debug('Creating new sync group node')
|
log.debug('Creating new sync group node')
|
||||||
@ -220,19 +220,33 @@ class PILLAR_OT_sync(async_loop.AsyncModalOperatorMixin, bpy.types.Operator):
|
|||||||
# First upload the file...
|
# First upload the file...
|
||||||
file_id = await pillar.upload_file(self.home_project_id, file_path,
|
file_id = await pillar.upload_file(self.home_project_id, file_path,
|
||||||
future=self.signalling_future)
|
future=self.signalling_future)
|
||||||
# Then attach it to a new node.
|
# Then attach it to a node.
|
||||||
node_props = {'project': self.home_project_id,
|
node_props = {'project': self.home_project_id,
|
||||||
'node_type': 'asset',
|
'node_type': 'asset',
|
||||||
'parent': self.sync_group_id,
|
'parent': self.sync_group_id,
|
||||||
'name': file_path.name,
|
'name': file_path.name}
|
||||||
'properties': {'file': file_id},
|
node = await pillar_call(pillarsdk.Node.find_first, {
|
||||||
'user': self.user_id}
|
'where': node_props,
|
||||||
|
}, caching=False)
|
||||||
|
|
||||||
|
if node is None:
|
||||||
|
# We're going to create a new node, so complete it.
|
||||||
|
log.debug('Creating new asset node')
|
||||||
|
node_props['user'] = self.user_id
|
||||||
|
node_props['properties'] = {'file': file_id}
|
||||||
|
|
||||||
node = pillarsdk.Node.new(node_props)
|
node = pillarsdk.Node.new(node_props)
|
||||||
created_ok = await pillar_call(node.create)
|
created_ok = await pillar_call(node.create)
|
||||||
if not created_ok:
|
if not created_ok:
|
||||||
log.error('Blender Cloud addon: unable to create asset node on the Cloud for file %s.',
|
log.error('Blender Cloud addon: unable to create asset node on the Cloud for file %s.', file_path)
|
||||||
file_path)
|
raise pillar.PillarError('Unable to create asset node on the Cloud for file %s' % file_path.name)
|
||||||
raise pillar.PillarError('Unable to create asset node on the Cloud for file %s' % file_path)
|
else:
|
||||||
|
# Update the existing node.
|
||||||
|
node.properties = {'file': file_id}
|
||||||
|
updated_ok = await pillar_call(node.update)
|
||||||
|
if not updated_ok:
|
||||||
|
log.error('Blender Cloud addon: unable to update asset node on the Cloud for file %s.', file_path)
|
||||||
|
raise pillar.PillarError('Unable to update asset node on the Cloud for file %s' % file_path.name)
|
||||||
|
|
||||||
return node
|
return node
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user