mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-11-07 12:16:12 +08:00
Don't copy outputs when converting smart cell to code (#2348)
This commit is contained in:
parent
072b8eef82
commit
a5dd74061c
2 changed files with 4 additions and 37 deletions
|
|
@ -1142,14 +1142,12 @@ defmodule Livebook.Session do
|
||||||
Notebook.fetch_cell_and_section(state.data.notebook, cell_id) do
|
Notebook.fetch_cell_and_section(state.data.notebook, cell_id) do
|
||||||
index = Enum.find_index(section.cells, &(&1 == cell))
|
index = Enum.find_index(section.cells, &(&1 == cell))
|
||||||
chunks = cell.chunks || [{0, byte_size(cell.source)}]
|
chunks = cell.chunks || [{0, byte_size(cell.source)}]
|
||||||
chunk_count = length(chunks)
|
|
||||||
|
|
||||||
state =
|
state =
|
||||||
for {{offset, size}, chunk_idx} <- Enum.with_index(chunks), reduce: state do
|
for {{offset, size}, chunk_idx} <- Enum.with_index(chunks), reduce: state do
|
||||||
state ->
|
state ->
|
||||||
outputs = if(chunk_idx == chunk_count - 1, do: cell.outputs, else: [])
|
|
||||||
source = binary_part(cell.source, offset, size)
|
source = binary_part(cell.source, offset, size)
|
||||||
attrs = %{source: source, outputs: outputs}
|
attrs = %{source: source}
|
||||||
cell_idx = index + chunk_idx
|
cell_idx = index + chunk_idx
|
||||||
cell_id = Utils.random_id()
|
cell_id = Utils.random_id()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -178,8 +178,7 @@ defmodule Livebook.SessionTest do
|
||||||
assert_receive {:operation, {:delete_cell, _client_id, ^cell_id}}
|
assert_receive {:operation, {:delete_cell, _client_id, ^cell_id}}
|
||||||
|
|
||||||
assert_receive {:operation,
|
assert_receive {:operation,
|
||||||
{:insert_cell, _client_id, ^section_id, 0, :code, _id,
|
{:insert_cell, _client_id, ^section_id, 0, :code, _id, %{source: "content"}}}
|
||||||
%{source: "content", outputs: []}}}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "inserts multiple cells when the smart cell has explicit chunks" do
|
test "inserts multiple cells when the smart cell has explicit chunks" do
|
||||||
|
|
@ -206,40 +205,10 @@ defmodule Livebook.SessionTest do
|
||||||
assert_receive {:operation, {:delete_cell, _client_id, ^cell_id}}
|
assert_receive {:operation, {:delete_cell, _client_id, ^cell_id}}
|
||||||
|
|
||||||
assert_receive {:operation,
|
assert_receive {:operation,
|
||||||
{:insert_cell, _client_id, ^section_id, 0, :code, _id,
|
{:insert_cell, _client_id, ^section_id, 0, :code, _id, %{source: "chunk 1"}}}
|
||||||
%{source: "chunk 1", outputs: []}}}
|
|
||||||
|
|
||||||
assert_receive {:operation,
|
assert_receive {:operation,
|
||||||
{:insert_cell, _client_id, ^section_id, 1, :code, _id,
|
{:insert_cell, _client_id, ^section_id, 1, :code, _id, %{source: "chunk 2"}}}
|
||||||
%{source: "chunk 2", outputs: [{1, terminal_text("Hello")}]}}}
|
|
||||||
end
|
|
||||||
|
|
||||||
test "doesn't garbage collect input values" do
|
|
||||||
input = %{
|
|
||||||
type: :input,
|
|
||||||
ref: "ref",
|
|
||||||
id: "input1",
|
|
||||||
destination: :noop,
|
|
||||||
attrs: %{type: :text, default: "hey", label: "Name", debounce: :blur}
|
|
||||||
}
|
|
||||||
|
|
||||||
smart_cell = %{
|
|
||||||
Notebook.Cell.new(:smart)
|
|
||||||
| kind: "text",
|
|
||||||
source: "content",
|
|
||||||
outputs: [{1, 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_infos: %{"input1" => %{value: "hey"}}} = Session.get_data(session.pid)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue