Skip to content

fix(journal): find journal pages by their day, not their formatted title - #13883

Open
yuxi-liu-wired wants to merge 7 commits into
logseq:masterfrom
yuxi-liu-wired:fix/dbtest-1046
Open

yuxi-liu-wired wants to merge 7 commits into
logseq:masterfrom
yuxi-liu-wired:fix/dbtest-1046

Conversation

@yuxi-liu-wired

@yuxi-liu-wired yuxi-liu-wired commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Fixes logseq/db-test#1046.

Refs logseq/db-test#884.

What the user sees

With a journal title format other than the default "MMM do, yyyy" (for example "yyyy-MM-dd"), several places miss the journal page of a day:

  • Clicking the date of a Deadline or Scheduled value leads to no page (Heading converted back to a block automatically #1046).
  • The previous/next/tomorrow journal shortcuts and the mobile journal calendar don't find an existing journal, and try to create one instead.
  • Quick Add finds no "today" page to move its blocks into.
  • A date typed into the page-search popup ("tomorrow", "next friday") is not matched with the existing journal.
  • The worker's guard that skips creating today's journal twice never recognises that today's journal exists.

Journals created before 69c4d36 keep a :block/name in the user's format while newer ones get the default format (#884), so name lookups fail for part of a graph whatever the configured format.

Cause

A journal's stable key is :block/journal-day (a yyyyMMdd int). Its :block/name is the default-format title, and its :block/title is in the configured format. These call sites looked the page up by a formatted name (date/journal-name, date/today, the title), which only matches when the configured format is the default one and the journal was created after 69c4d36.

Change

The journal page of a date is now resolved with ldb/get-journal-page-by-day (db-async/<get-journal-page-by-day from the UI). Days with no journal page yet behave as before: they are created with a title in the configured format, and the Deadline/Scheduled link falls back to the default-format name. Labels and titles shown to the user keep the configured format.

Sites changed:

Site Before After
components/property/value.cljs datetime-value (Deadline/Scheduled link) {:block/name (date/journal-name date)} new journal-date-link resolves the page by :block/journal-day and links by uuid; falls back to date/journal-block-name (default format) when the day has no page
handler/journal.cljs go-to-tomorrow/prev/next <get-block + <page-exists? by date/journal-name <get-journal-page-by-day; the current day comes from the page's :block/journal-day; day arithmetic with journal-day-plus; a missing journal is created with date/journal-day->journal-name
mobile/components/header.cljs journal calendar <get-block by date/journal-name <get-journal-page-by-day
handler/editor/quick_add.cljs (ensure + move blocks) <get-block(-with-children) by (date/today) <get-journal-page-by-day by date/today-journal-day, then by uuid
handler/page.cljs natural-language date in the page-search popup pulled [:block/name (lc title)] (<page-by-title) <journal-page-by-day
worker/handler/transaction.cljs + deps/outliner/.../page.cljs create-today-journal guard tx-meta :today-journal-name, ldb/get-page by name tx-meta :today-journal-day, ldb/get-journal-page-by-day
date.cljs new journal-block-name, journal-day->journal-name, aliases ms->journal-day, date->journal-day, journal-day-plus

Sites already using the journal day (left as is): graph-parser/block.cljs page-name-string->map, outliner/template.cljs, outliner/op.cljs, db-sync/.../semantic.cljs ensure-today-page!, worker/pipeline.cljs, worker/commands.cljs, handler/route.cljs (sidebar-journals!), handler/page.cljs <today-journal-page, components/quick_add.cljs, db/async.cljs <get-today-journal-title and <get-journal-page-title, worker/query_dsl.cljs ->journal-day-int, components/page.cljs today?.

Sites left on purpose (they build or parse a title, they don't look a page up by name):

  • date/journal-name, date/today, date/tomorrow, date/yesterday used for display and for page-ref text (template.cljs, commands.cljs, datepicker.cljs, query/builder.cljs, the date picker in property/value.cljs): the text [[<title>]] is converted to a journal day when the block is saved (convert-page-if-journal).
  • handler/events.cljs :page/create, handler/repo.cljs, handler/page.cljs create-today-journal!: create by title; the outliner derives the journal day and the deterministic uuid from the title.
  • components/scheduled_deadlines.cljs and db/async.cljs <get-date-scheduled-or-deadlines: parse the title of today's page to its day (the page is already known to be today by its :block/journal-day). Passing the day would be a cleaner signature but is a refactor.
  • components/right_sidebar.cljs get-page: derives a route name, no lookup.
  • deps/outliner/.../validate.cljs, deps/graph-parser/.../exporter.cljs, deps/db/.../build.cljs, outliner/core.cljs (a rename keeps the default-format :block/name): title/name generation, not lookups.

#884

The UI paths above no longer depend on the journal's :block/name, so the mixed name formats of old and new journals no longer break navigation, links and Quick Add. Not covered: the plugin API (getPage, pushState with a journal title such as "2026-05-18", the case in the issue) and any other code that calls ldb/get-page with a formatted journal title still match :block/name. Fixing those needs either a plugin-API decision (resolve a journal title by day in get-page) or a migration that rewrites old journals' :block/name to the default format. Neither is included here.

Tests

Each of these fails on master and passes with the change (build without the fix: 5 failures in these namespaces; with the fix: 0 failures, and the whole unit suite passes):

  • frontend.handler.journal-test (new): next/prev/tomorrow with the "yyyy-MM-dd" format open the existing journal whose :block/name is in the default format, or create the missing one with a title in the configured format.
  • frontend.handler.editor-async-test/quick-add-moves-blocks-to-today-journal-found-by-journal-day.
  • frontend.worker.db-core-test/transact-skips-when-today-journal-already-exists: now with a custom-format title and a default-format :block/name; it also asserts that the skipped transaction isn't applied.
  • frontend.components.property.value-test/deadline-date-links-to-journal-page-by-journal-day-test: the Deadline/Scheduled link target is the existing journal's uuid with the "yyyy-MM-dd" format, and the default-format name when the day has no page. This one only fails on master because the function it calls doesn't exist there; the component itself isn't rendered (effects don't run in the static renderer).
  • frontend.date-test/journal-block-name-test.

deps/outliner tests (pnpm test) pass too (tx-meta key change).


Devin Review

Added: journal refs and titles, found by a journal fuzzer

Fixes logseq/db-test#921, Fixes logseq/db-test#1168, Fixes logseq/db-test#1293.

Five commits found with a journal fuzzer (built-in and random custom date formats, [[date]] and /today refs as the editor makes them, recycle/restore/GC, format changes; it checks that a ref never renames a journal, titles are never blank, a recycled journal never hides its day, one journal per day). It finds 248 violations over 250 sequences on master and 0 with these commits (700 sequences).

What the user sees

  • searching for an "existing" page and click enter tries to create it #1168: on a client whose Journal class has no :logseq.property.journal/title-format, every date reference renders as an empty [[]]; other clients show the dates. Creating a journal there also makes a plain page, so the day has no journal.
  • 局部页面图谱不自动刷新=Local page graph does not refresh automatically.  #1293: with the date format E, dd.MM.yyyy, /today inserts [[Fri, 25.09.2026]] and the editor cannot save the block or leave it (Enter and Escape do nothing) until the brackets are removed. The same family: after the date format was changed on another client and before the editor reloads, a typed [[date]] or /today creates a plain page that holds the day's journal uuid, so that day never gets a journal; creating today's journal with the editor's stale format makes a plain page too.
  • Fix find-position #921: a deleted (recycled) journal keeps its day: today's journal is not created ("a page exists"), and [[date]] refs to that day link to the hidden node. Plausible cause of "Journal stuck on June 4th", not confirmed with the reporter.

Cause

  • searching for an "existing" page and click enter tries to create it #1168: a journal's title is computed from its day and the Journal class's title-format, and date-time-util/format returns nil without a formatter, so get-journal-title returned nil. outliner-page/create also parsed titles with the stored format only, and with none a title parses to no day.
  • 局部页面图谱不自动刷新=Local page graph does not refresh automatically.  #1293: resolve-page-ref finds no page by the ref's name (journal names stay in the default format) and calls outliner-page/create, which finds the existing journal through its day and returns only its uuid. The ref was built from the typed title and name plus that uuid, so the existing journal was renamed from sep 25th, 2026 to fri, 25.09.2026, and ensure-journal-page-protected-attrs-not-updated! rejected the write (the logged :before/:after). When the editor parses a ref as a journal and the graph's format does not, create got the editor's title, found no day and built a non-journal page with the journal's uuid.
  • Fix find-position #921: ldb/get-journal-page-by-day returned recycled nodes, so create-today-journal! and the other "does the day have a journal" checks said yes; resolve-page-ref found a journal ref by name, recycled pages included, and never reached the restore in create.

Change

One commit per cause:

Tests

Each fails on master and passes with its fix.

deps/db and deps/outliner whole nbb suites and the whole pnpm cljs:run-test suite pass with the fixes. A journal fuzzer (random date formats, UI/db format mismatch, missing title-format, recycle/restore/GC, legacy-named journals, [[date]] refs through insert-blocks!) found 144 violations on the first three commits' state (and 248 on master) over 250 sequences, and none on this branch over 700 sequences.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

yuxi-liu-wired pushed a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 30, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 30, 2026
… formatted title (squashed: its commits conflicted one by one with the stack)
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 31, 2026
… formatted title (squashed: its commits conflicted one by one with the stack)
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 1, 2026
… formatted title (squashed: its commits conflicted one by one with the stack)
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 2, 2026
… formatted title (squashed: its commits conflicted one by one with the stack)
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 3, 2026
… formatted title (squashed: its commits conflicted one by one with the stack)
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 4, 2026
… formatted title (squashed: its commits conflicted one by one with the stack)
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 11, 2026
… formatted title (squashed: its commits conflicted one by one with the stack)
@yuxi-liu-wired
yuxi-liu-wired force-pushed the fix/dbtest-1046 branch 2 times, most recently from 94d3d2b to 503cc55 Compare November 12, 2026 12:01
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 12, 2026
… formatted title (squashed: its commits conflicted one by one with the stack)
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 13, 2026
… formatted title (squashed: its commits conflicted one by one with the stack)
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 14, 2026
… formatted title (squashed: its commits conflicted one by one with the stack)
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 15, 2026
… formatted title (squashed: its commits conflicted one by one with the stack)
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 16, 2026
… formatted title (squashed: its commits conflicted one by one with the stack)
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 17, 2026
… formatted title (squashed: its commits conflicted one by one with the stack)
@yuxi-liu-wired
yuxi-liu-wired force-pushed the fix/dbtest-1046 branch 2 times, most recently from f054fd8 to 015f2a8 Compare November 18, 2026 14:34
…th any journal title format

With a journal title format other than the default "MMM do, yyyy" (for example "yyyy-MM-dd"), clicking the date pill of a Deadline or Scheduled value led to no page.

The pill is rendered as a page reference by name, using date/journal-name, which formats the day in the configured journal title format. A journal's :block/name is always the default-format title, so the lookup by name found no page.

Add date/journal-block-name, which formats a date with the default journal title format, and use it for the Deadline/Scheduled page reference. The visible label is unchanged.

Test: journal-block-name-test in frontend.date-test checks the name stays in the default format while journal-name follows the configured format.

Fixes logseq/db-test#1046
…ed name

With a journal title format other than the default "MMM do, yyyy", several journal shortcuts silently missed the journal page: the previous/next/tomorrow journal commands and the mobile calendar created or opened the wrong page, Quick Add found no "today" page to move blocks into, the date typed into the page-search popup did not match the existing journal, and the transaction that guards creating today's journal never recognised that today's journal existed. The Deadline/Scheduled date link was the same problem in the properties UI.

A journal's :block/name is the default-format title (journals created before 69c4d36 even keep one in the user's format), while these call sites looked pages up by date/journal-name or date/today, which use the configured format. The stable key is :block/journal-day.

Resolve the journal page for a date with ldb/get-journal-page-by-day (db-async/<get-journal-page-by-day on the UI side) at these sites: the Deadline/Scheduled date link, go-to-tomorrow/prev/next journal, the mobile journal calendar, Quick Add, the natural-language date in the page-search popup, and the create-today-journal guard in the worker transaction (tx-meta :today-journal-name becomes :today-journal-day). Days without a journal page keep working as before: they are created with a title in the configured format, and the date link falls back to the default-format name. Displayed titles and labels keep the configured format.

Tests: journal-test (go-to-next/prev/tomorrow), quick-add-moves-blocks-to-today-journal-found-by-journal-day, transact-skips-when-today-journal-already-exists (now with a custom-format title and a default-format :block/name) and deadline-date-links-to-journal-page-by-journal-day-test.

Refs logseq/db-test#884
Fixes logseq/db-test#1046
…ault format

A graph whose Journal class had lost :logseq.property.journal/title-format on one client computed no journal title at all, so every date reference there rendered as an empty [[]] while other clients showed the dates.

A journal's title is computed from its day and the Journal class's title-format, and logseq.common.util.date-time/format returns nil when there is no formatter. get-journal-title now falls back to the default 'MMM do, yyyy' format, the one the renderer's date-formatter lookup already defaults to.

Test: deps/db logseq.db-test/journal-title-without-title-format-uses-default-format retracts the format and checks the computed title.

Fixes logseq/db-test#1168
…rmat no longer renames the journal

With the date format 'E, dd.MM.yyyy', /today inserted [[Fri, 25.09.2026]] and the editor then could not save the block or leave it: the write was rejected with 'journal page protected attr updated' because the ref renamed the existing journal from 'sep 25th, 2026' to 'fri, 25.09.2026'.

resolve-page-ref finds no page by the ref's name (journal names stay in the default format) and calls outliner-page/create, which finds the existing journal through its day and returns only its uuid. The ref was then built from the typed title and name plus that uuid, i.e. the journal's uuid with a new name. When create returns an existing journal, resolve-page-ref now takes the title and name from that journal, as the get-page branch just above it does.

Test: frontend.worker.pipeline-test/save-block-ref-to-existing-journal-keeps-journal-name-with-custom-date-format-test saves a block referencing the journal under a custom title-format; on master it throws the logged :before/:after error.

Fixes logseq/db-test#1293
…s journal and date refs

A journal the user deleted (recycled) kept its day: the Journals list had no live journal for it, creating today's journal was skipped because "a page exists", and a [[date]] ref (typed, /today, /tomorrow) linked to the hidden recycled node and left it recycled.

`ldb/get-journal-page-by-day` returned the recycled node, so every caller that asks "does this day have a journal?" (create-today-journal!, the pipeline's template journals, the db-sync today page, the thread-api the UI asks) got a yes. `resolve-page-ref` found a journal ref by its name (`ldb/get-page`), recycled pages included, so it never reached `outliner-page/create`, where the restore lives.

`get-journal-page-by-day` skips recycled journals. `resolve-page-ref` looks a journal ref up by its day instead of its name; when no live journal exists `create` runs and restores the recycled one.

Tests: `logseq.db-test/get-journal-page-by-day-skips-recycled-journal`, `logseq.outliner.core-test/insert-blocks-ref-to-recycled-journal-restores-it`.

Fixes logseq/db-test#921
…h does not no longer makes a plain page that owns the journal's uuid

After the date format was changed on another client (or by sync) and before the editor was reloaded, a [[date]] ref typed or inserted with /today in the old format created a plain page holding the day's journal uuid. That day then never got a journal: creating it returned the plain page, and every later ref to the day linked to the plain page.

The editor parses the ref with its own format and sends it as a journal with the journal's uuid. `resolve-page-ref` passed the ref's title to `outliner-page/create`, which parses titles with the graph's format, found no day and built a non-journal page with the ref's uuid. The ref was also built from the typed title and name, so a journal `create` made kept the editor's title and name.

`resolve-page-ref` creates a journal ref from its day written in the default format, which `create` always parses, and takes the title and name of the journal that `create` found or made, not the ref's.

Test: `logseq.outliner.core-test/insert-blocks-ref-parsed-as-journal-only-by-the-editor-makes-the-journal`.

Related to logseq/db-test#1293
…th today's title in a stale editor format

On a graph whose Journal class has no `:logseq.property.journal/title-format`, creating a journal (the [[ page-search create, /today) made a plain page, so the day had no journal. The same happened to today's journal when the editor's date format differed from the graph's (changed on another client, not reloaded): the editor asks for today's journal with a title the graph's format cannot parse.

`outliner-page/create` parsed the title with the stored format only, which is nil without a title-format, and with a nil format a title parses to no day. For today's journal the title is the editor's, not necessarily the graph's.

`create` falls back to the default format when none is stored, and for a today's-journal request whose title parses to no day it uses today's date in the default format.

Tests: `logseq.outliner.core-test/create-journal-without-title-format`, `logseq.outliner.core-test/create-today-journal-with-title-in-a-stale-editor-format`.

Related to logseq/db-test#1168

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

1 participant