Trigger input garbage collection after cell deletion

This commit is contained in:
Jonatan Kłosko 2023-01-05 12:34:32 +01:00
parent f1deaead34
commit 35b8bb73df
2 changed files with 24 additions and 0 deletions

View file

@ -367,6 +367,7 @@ defmodule Livebook.Session.Data do
data
|> with_actions()
|> delete_section(section, delete_cells)
|> garbage_collect_input_values()
|> update_validity_and_evaluation()
|> update_smart_cell_bases(data)
|> set_dirty()
@ -382,6 +383,7 @@ defmodule Livebook.Session.Data do
data
|> with_actions()
|> delete_cell(cell, section)
|> garbage_collect_input_values()
|> update_validity_and_evaluation()
|> update_smart_cell_bases(data)
|> set_dirty()

View file

@ -827,6 +827,28 @@ defmodule Livebook.Session.DataTest do
[{%{id: "setup"}, %{id: "setup-section"}}]}
]} = Data.apply_operation(data, operation)
end
test "garbage collects input values that are no longer used" do
input = %{id: "i1", type: :text, label: "Text", default: "hey"}
data =
data_after_operations!([
{:insert_section, @cid, 0, "s1"},
{:insert_cell, @cid, "s1", 0, :code, "c1", %{}},
{:set_runtime, @cid, connected_noop_runtime()},
evaluate_cells_operations(["setup"]),
{:queue_cells_evaluation, @cid, ["c1"]},
{:add_cell_evaluation_response, @cid, "c1", {:input, input}, eval_meta()},
{:set_input_value, @cid, "i1", "value"}
])
operation = {:delete_cell, @cid, "c1"}
empty_map = %{}
assert {:ok, %{input_values: ^empty_map}, actions} = Data.apply_operation(data, operation)
assert {:clean_up_input_values, %{"i1" => "value"}} in actions
end
end
describe "apply_operation/2 given :restore_cell" do