mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-02-24 23:09:23 +08:00
Don't garbage collect input values when converting smart cell to code (#1781)
This commit is contained in:
parent
e019eae161
commit
07fab99353
2 changed files with 43 additions and 13 deletions
|
@ -999,21 +999,22 @@ defmodule Livebook.Session do
|
|||
chunks = cell.chunks || [{0, byte_size(cell.source)}]
|
||||
chunk_count = length(chunks)
|
||||
|
||||
state = handle_operation(state, {:delete_cell, client_id, cell.id})
|
||||
state =
|
||||
for {{offset, size}, chunk_idx} <- Enum.with_index(chunks), reduce: state do
|
||||
state ->
|
||||
outputs = if(chunk_idx == chunk_count - 1, do: cell.outputs, else: [])
|
||||
source = binary_part(cell.source, offset, size)
|
||||
attrs = %{source: source, outputs: outputs}
|
||||
cell_idx = index + chunk_idx
|
||||
cell_id = Utils.random_id()
|
||||
|
||||
for {{offset, size}, chunk_idx} <- Enum.with_index(chunks), reduce: state do
|
||||
state ->
|
||||
outputs = if(chunk_idx == chunk_count - 1, do: cell.outputs, else: [])
|
||||
source = binary_part(cell.source, offset, size)
|
||||
attrs = %{source: source, outputs: outputs}
|
||||
cell_idx = index + chunk_idx
|
||||
cell_id = Utils.random_id()
|
||||
handle_operation(
|
||||
state,
|
||||
{:insert_cell, client_id, section.id, cell_idx, :code, cell_id, attrs}
|
||||
)
|
||||
end
|
||||
|
||||
handle_operation(
|
||||
state,
|
||||
{:insert_cell, client_id, section.id, cell_idx, :code, cell_id, attrs}
|
||||
)
|
||||
end
|
||||
handle_operation(state, {:delete_cell, client_id, cell.id})
|
||||
else
|
||||
_ -> state
|
||||
end
|
||||
|
|
|
@ -198,6 +198,35 @@ defmodule Livebook.SessionTest do
|
|||
{:insert_cell, _client_id, ^section_id, 1, :code, _id,
|
||||
%{source: "chunk 2", outputs: [{1, {:text, "Hello"}}]}}}
|
||||
end
|
||||
|
||||
test "doesn't garbage collect input values" do
|
||||
input = %{
|
||||
ref: :input_ref,
|
||||
id: "input1",
|
||||
type: :text,
|
||||
label: "Name",
|
||||
default: "hey",
|
||||
destination: :noop
|
||||
}
|
||||
|
||||
smart_cell = %{
|
||||
Notebook.Cell.new(:smart)
|
||||
| kind: "text",
|
||||
source: "content",
|
||||
outputs: [{1, {:input, input}}]
|
||||
}
|
||||
|
||||
section = %{Notebook.Section.new() | cells: [smart_cell]}
|
||||
notebook = %{Notebook.new() | sections: [section]}
|
||||
|
||||
session = start_session(notebook: notebook)
|
||||
|
||||
Session.subscribe(session.id)
|
||||
|
||||
Session.convert_smart_cell(session.pid, smart_cell.id)
|
||||
|
||||
assert %{input_values: %{"input1" => "hey"}} = Session.get_data(session.pid)
|
||||
end
|
||||
end
|
||||
|
||||
describe "add_dependencies/2" do
|
||||
|
|
Loading…
Reference in a new issue