Drop cell source text from data in LV when no longer needed (#342)

This commit is contained in:
Jonatan Kłosko 2021-06-10 15:41:40 +02:00 committed by GitHub
parent b0ace783ea
commit e02bcce0bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View file

@ -791,7 +791,9 @@ defmodule Livebook.Session.Data do
Delta.transform(delta_ahead, transformed_new_delta, :left)
end)
new_source = JSInterop.apply_delta_to_string(transformed_new_delta, cell.source)
# Note: the session LV drops cell's source once it's no longer needed
new_source =
cell.source && JSInterop.apply_delta_to_string(transformed_new_delta, cell.source)
data_actions
|> set!(notebook: Notebook.update_cell(data.notebook, cell.id, &%{&1 | source: new_source}))

View file

@ -333,6 +333,10 @@ defmodule LivebookWeb.SessionLive do
evaluation_digest: encode_digest(info.evaluation_digest)
}
# From this point on we don't need cell source in the LV,
# so we are going to drop it altogether
socket = remove_cell_source(socket, cell_id)
{:reply, payload, socket}
:error ->
@ -761,6 +765,12 @@ defmodule LivebookWeb.SessionLive do
defp encode_digest(nil), do: nil
defp encode_digest(digest), do: Base.encode64(digest)
defp remove_cell_source(socket, cell_id) do
update_in(socket.private.data.notebook, fn notebook ->
Notebook.update_cell(notebook, cell_id, &%{&1 | source: nil})
end)
end
# Builds view-specific structure of data by cherry-picking
# only the relevant attributes.
# We then use `@data_view` in the templates and consequently
@ -833,6 +843,8 @@ defmodule LivebookWeb.SessionLive do
%{
id: cell.id,
type: :elixir,
# Note: we need this during initial loading,
# at which point we still have the source
empty?: cell.source == "",
outputs: cell.outputs,
validity_status: info.validity_status,
@ -844,6 +856,8 @@ defmodule LivebookWeb.SessionLive do
%{
id: cell.id,
type: :markdown,
# Note: we need this during initial loading,
# at which point we still have the source
empty?: cell.source == ""
}
end