Skip to content

Seed the movies demo once instead of on every boot - #5

Open
tamohannes wants to merge 1 commit into
nustackdev:mainfrom
tamohannes:fix/movies-demo-seeds-once
Open

Seed the movies demo once instead of on every boot#5
tamohannes wants to merge 1 commit into
nustackdev:mainfrom
tamohannes:fix/movies-demo-seeds-once

Conversation

@tamohannes

Copy link
Copy Markdown

nu demo movies throws away everything you log the moment you restart it.

init ran on every boot and set the whole shelf unconditionally:

init = nu.kv.Transaction(
    State.total.set(len(_SEED_MOVIES))
    | ...
    | State.movies.set(_SEED_MOVIES)
    | State.selected.set(0),
)

So the second start overwrites the store with the four samples. The About page inside that same demo says "Every row lives in rocksdb. Restart, everything is still there," which makes it the worst place for this to happen: persistence is the claim the demo exists to make.

Fix

Guard the seed on State.total.missing() so it fires only against a store that has never been written. selected stays an unconditional set, since it is a cursor into the detail page rather than user data. Both copies get the change, examples/movies.py and the bundled nu demo movies.

Why not .init()

That was the first attempt, since counter, sampled and telegram_echo all seed with .init() and it reads better. On an empty store it left the shelf empty: the item leaves seeded, and State.movies.init(_SEED_MOVIES) wrote nothing, so Missing on a ShapesListRef seems to be false even before anything is written. Might be intended for collection Forms, might be worth its own look. Guarding on one item leaf sidesteps it and has the nicer property of making the seed all or nothing.

Verification

Store wiped between runs, then:

before after
first start, empty store seeds 4 rows seeds 4 rows
restart with a 5th row added to _SEED_MOVIES 5th row appears in the store, existing rows replaced store untouched, original rows intact

Editing the seed list is a stand in for a row you logged yourself: it proves whether boot number two writes over what is already there.

🤖 Generated with Claude Code

`init` set the whole shelf unconditionally, so starting the demo a second time
replaced everything the user had logged with the four sample rows. The About
page in that same demo says "Every row lives in rocksdb. Restart, everything is
still there."

Guard the seed on `State.total.missing()` so it fires only against a store that
has never been written. `selected` stays unconditional: it is a cursor into the
detail page, not user data.

Same change in both copies, `examples/movies.py` and the bundled `nu demo
movies`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant