Skip to content

Commit

Permalink
Feat(dui3): sketchup send batches sequentially (#397)
Browse files Browse the repository at this point in the history
* feat: send batches in sequence and create commit later

* Remove load tests
  • Loading branch information
oguzhankoral authored Dec 12, 2024
1 parent 3e5ba13 commit 5e6825b
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 16 deletions.
36 changes: 36 additions & 0 deletions speckle_connector_3/src/actions/send_actions/after_send_objects.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

require_relative '../action'
require_relative '../../convertors/to_native'
require_relative '../../convertors/to_native_v2'

module SpeckleConnector3
module Actions
# After objects send to server.
class AfterSendObjects < Action
# @param state [States::State] the current state of the {App::SpeckleConnectorApp}
# @return [States::State] the new updated state object
def self.update_state(state, resolve_id, model_card_id, referenced_object_id)
model_card = state.speckle_state.send_cards[model_card_id]
account = Accounts.get_account_by_id(model_card.account_id)
args = {
modelCardId: model_card_id,
projectId: model_card.project_id,
modelId: model_card.model_id,
token: account['token'],
serverUrl: account['serverInfo']['url'],
accountId: model_card.account_id,
message: model_card.message,
referencedObjectId: referenced_object_id,
sendConversionResults: state.speckle_state.conversion_results[model_card_id]
}

after_send_object_js_script = "sendBinding.emit('createVersionViaBrowser', #{args.to_json})"
state = state.with_add_queue_js_command('createVersionViaBrowser', after_send_object_js_script)

resolve_js_script = "sendBinding.receiveResponse('#{resolve_id}')"
state.with_add_queue_js_command('afterSendObject', resolve_js_script)
end
end
end
end
52 changes: 37 additions & 15 deletions speckle_connector_3/src/actions/send_actions/send.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,44 @@ def self.update_state(state, resolve_id, model_card_id)

resolve_js_script = "sendBinding.receiveResponse('#{resolve_id}')"
state = state.with_add_queue_js_command('send', resolve_js_script)
args = {
modelCardId: model_card_id,
projectId: model_card.project_id,
modelId: model_card.model_id,
token: account['token'],
serverUrl: account['serverInfo']['url'],
accountId: model_card.account_id,
message: model_card.message,
sendConversionResults: converter.conversion_results,
sendObject: {
id: id,
batches: batches
# args = {
# modelCardId: model_card_id,
# projectId: model_card.project_id,
# modelId: model_card.model_id,
# token: account['token'],
# serverUrl: account['serverInfo']['url'],
# accountId: model_card.account_id,
# message: model_card.message,
# sendConversionResults: converter.conversion_results,
# sendObject: {
# id: id,
# batches: batches
# }
# }
# js_script = "sendBinding.emit('sendViaBrowser', #{args.to_json})"
# state.with_add_queue_js_command('sendViaBrowser', js_script)

# store conversion results in state to pick up later
new_speckle_state = state.speckle_state.with_conversion_results(model_card_id, converter.conversion_results)
state = state.with_speckle_state(new_speckle_state)

total_batch_count = batches.count
batches.each_with_index do |batch, i|
current_batch = i + 1
args = {
modelCardId: model_card_id,
projectId: model_card.project_id,
token: account['token'],
serverUrl: account['serverInfo']['url'],
batch: batch,
currentBatch:current_batch,
totalBatch: total_batch_count,
referencedObjectId: id
}
}
js_script = "sendBinding.emit('sendViaBrowser', #{args.to_json})"
state.with_add_queue_js_command('sendViaBrowser', js_script)
js_script = "sendBinding.emit('sendBatchViaBrowser', #{args.to_json})"
state = state.with_add_queue_js_command("sendBatchViaBrowser_#{current_batch}", js_script)
end
state
end
end
end
Expand Down
14 changes: 14 additions & 0 deletions speckle_connector_3/src/states/speckle_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class SpeckleState
# @return [Immutable::Hash{String=>Cards::ReceiveCard}] receive cards.
attr_reader :receive_cards

# @return [Immutable::Hash{String=>Array<UiData::Report::ConversionResult>}] receive cards.
attr_reader :conversion_results

# @return [Immutable::Hash{String=>Immutable::Hash{String=>SpeckleObjects::ObjectReference}}] object references that sent before server.
attr_reader :object_references_by_project

Expand Down Expand Up @@ -70,6 +73,7 @@ def initialize(accounts, observers, queue, stream_queue)
@definitions = Immutable::EmptyHash
@send_cards = Immutable::EmptyHash
@receive_cards = Immutable::EmptyHash
@conversion_results = Immutable::EmptyHash
@relation = Relations::ManyToOneRelation.new
@speckle_mapper_state = SpeckleMapperState.new
end
Expand Down Expand Up @@ -218,6 +222,16 @@ def with_object_references(project_id, references)
with(:@object_references_by_project => object_references_by_project.put(project_id, new_project_references))
end

def with_conversion_results(model_card_id, results)
new_conversion_results = conversion_results.put(model_card_id, results)
with(:@conversion_results => new_conversion_results)
end

def without_conversion_results(model_card_id)
new_conversion_results = conversion_results.delete(model_card_id)
with(:@conversion_results => new_conversion_results)
end

def invalid_streams
speckle_entities.collect do |_id, speckle_entity|
speckle_entity.invalid_stream_ids
Expand Down
4 changes: 3 additions & 1 deletion speckle_connector_3/src/ui/bindings/send_binding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require_relative 'binding'
require_relative '../../actions/send_actions/send'
require_relative '../../actions/send_actions/after_send_objects'
require_relative '../../actions/base_actions/get_send_filters'
require_relative '../../actions/base_actions/get_send_settings'
require_relative '../../actions/base_actions/update_send_filter'
Expand All @@ -17,7 +18,8 @@ def commands
send: Commands::ActionCommand.new(@app, self, Actions::Send),
getSendFilters: Commands::ActionCommand.new(@app, self, Actions::GetSendFilters),
getSendSettings: Commands::ActionCommand.new(@app, self, Actions::GetSendSettings),
updateSendFilter: Commands::ActionCommand.new(@app, self, Actions::UpdateSendFilter)
updateSendFilter: Commands::ActionCommand.new(@app, self, Actions::UpdateSendFilter),
afterSendObjects: Commands::ActionCommand.new(@app, self, Actions::AfterSendObjects)
}.freeze
end
end
Expand Down

0 comments on commit 5e6825b

Please sign in to comment.