Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions apple/Sources/LogseqModel/Models.swift
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ public struct LogseqSearchHit: Codable, Hashable, Identifiable, Sendable {
public let isPage: Bool
public let page: LogseqSidebarPage?
public let breadcrumbs: [LogseqEntitySummary]
public let tags: [LogseqEntitySummary]

public var id: String { uuid }

Expand All @@ -343,17 +344,19 @@ public struct LogseqSearchHit: Codable, Hashable, Identifiable, Sendable {
title: String,
isPage: Bool,
page: LogseqSidebarPage? = nil,
breadcrumbs: [LogseqEntitySummary] = []
breadcrumbs: [LogseqEntitySummary] = [],
tags: [LogseqEntitySummary] = []
) {
self.uuid = uuid
self.title = title
self.isPage = isPage
self.page = page
self.breadcrumbs = breadcrumbs
self.tags = tags
}

private enum CodingKeys: String, CodingKey {
case uuid, title, isPage, page, breadcrumbs
case uuid, title, isPage, page, breadcrumbs, tags
}

public init(from decoder: Decoder) throws {
Expand All @@ -363,6 +366,7 @@ public struct LogseqSearchHit: Codable, Hashable, Identifiable, Sendable {
isPage = try values.decodeIfPresent(Bool.self, forKey: .isPage) ?? false
page = try values.decodeIfPresent(LogseqSidebarPage.self, forKey: .page)
breadcrumbs = try values.decodeIfPresent([LogseqEntitySummary].self, forKey: .breadcrumbs) ?? []
tags = try values.decodeIfPresent([LogseqEntitySummary].self, forKey: .tags) ?? []
}
}

Expand Down
45 changes: 43 additions & 2 deletions apple/Tests/UI/search-result-navigation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,14 @@ import UIKit
var routes: [String] = []
var query = ""
let hits: [[String: Any]] = (0..<80).map { index in
["uuid": "result-\(index)", "title": "Search result \(index)",
"isPage": index < 40]
var hit: [String: Any] = ["uuid": "result-\(index)", "title": "Search result \(index)",
"isPage": index < 40]
if index == 0 {
hit["title"] = "Child Page"
hit["breadcrumbs"] = [["uuid": "parent", "title": "Parent Page"]]
hit["tags"] = [["uuid": "projects", "title": "Projects"]]
}
return hit
}
func snapshot() -> String {
let nodes: [[String: Any]] = routes.map { uuid in
Expand All @@ -91,6 +97,9 @@ import UIKit
"outlinerRows": rows,
]
if revealsBlock { node["scrollTarget"] = uuid }
if uuid == "result-0" {
node["nodeProperties"] = ["ownerUuid": uuid, "canDelete": true, "hasChildPages": true]
}
return node
}
let result: [String: Any] = [
Expand Down Expand Up @@ -173,6 +182,16 @@ import UIKit
try await wait("Search must return page and block results") {
query == "Search" && find("search.result.result-0") != nil && find("search.result.result-40") != nil
}
func text(_ identifier: String) -> String? {
find(identifier).flatMap { backend.model(id: $0)?.property(.text)?.stringValue }
}
guard text("search.result.title.result-0") == "Child Page",
text("search.result.context.result-0") == "Parent Page",
text("search.result.tags.result-0") == "#Projects",
find("search.result.context.result-1") == nil,
find("search.result.tags.result-1") == nil else {
throw failure("Search rows must display the leaf title, parent page and tags when present")
}
try await Task.sleep(for: .milliseconds(200))
let root = window.rootViewController!
func searchNavigation() -> UINavigationController? {
Expand Down Expand Up @@ -256,6 +275,28 @@ import UIKit
try await Task.sleep(for: .milliseconds(500))
try sampler.verify("reopening")
}
let reopenedField = views(window).compactMap { $0 as? UISearchTextField }.first { $0.isFirstResponder }!
reopenedField.insertText("Parent Child")
try await wait("The child result appears for a namespace query") {
query == "Parent Child" && find("search.result.result-0") != nil
}
try backend.performPress(node: find("search.result.result-0")!)
try await wait("The parent result opens with its page actions") {
navigation.viewControllers.count == 2 && navigation.transitionCoordinator == nil
&& find("button.page.delete") != nil
}
try backend.performPress(node: find("button.page.delete")!)
try await wait("Deleting a parent presents a warning without a destructive action") {
find("dialog.page-delete.warning") != nil && find("button.page-delete.confirm") == nil
&& (root.presentedViewController != nil || navigation.presentedViewController != nil)
}
try await Task.sleep(for: .milliseconds(250))
try screenshot("page-deletion-warning.png")
try backend.performPress(node: find("button.page-delete.warning.dismiss")!)
try await wait("Dismissing the warning leaves the parent page open") {
find("dialog.page-delete.warning") == nil && navigation.viewControllers.count == 2
&& routes == ["result-0"]
}
guard runtime.lastError == nil else { throw failure(runtime.lastError!) }
print("PASS: search keeps a stable topbar through opening, page/block results, Back, Cancel, core dismissal, and reopening")
}
Expand Down
69 changes: 58 additions & 11 deletions shared/src/logseq/core/graph_read.ml
Original file line number Diff line number Diff line change
Expand Up @@ -194,18 +194,21 @@ let tag_is_visible_in_node db eid =
&& value db eid "logseq.property.class/hide-from-node"
<> Some (Ds.Bool true)

let visible_tag_summaries decrypt_title db eid =
let tag_summaries decrypt_title db eid visible =
List.of_seq (Ds.Db.datoms db Ds.Eavt ~e:eid ~a:"block/tags" ())
|> List.filter_map (fun (datom : Ds.datom) ->
match Ds_value.ref_eid db "block/tags" datom.v with
| Some tag_eid ->
if
tag_is_visible_in_node db tag_eid
visible tag_eid
&& entity_is_instance_of db tag_eid "logseq.class/Tag"
then entity_summary decrypt_title db tag_eid
else None
| None -> None)

let visible_tag_summaries decrypt_title db eid =
tag_summaries decrypt_title db eid (tag_is_visible_in_node db)

let rec breadcrumbs_loop decrypt_title db seen eid ancestors =
if List.mem eid seen then ancestors
else
Expand Down Expand Up @@ -402,10 +405,22 @@ let page_is_hidden db eid =
in
loop [] eid

let namespace_children db eid =
Ds_value.datoms_by_ref db Ds.Aevt "block/parent" eid
|> Seq.filter_map (fun (datom : Ds.datom) ->
match string_value (value db datom.e "block/name") with
| Some _ when value db datom.e "logseq.property/deleted-at" = None -> Some datom.e
| _ -> None)

let library_entity db eid =
value db eid "logseq.property/built-in?" = Some (Ds.Bool true)
&& string_value (value db eid "block/title") = Some "Library"

let namespace_parent db eid =
match ref_eids db eid "block/parent" with
| [parent] when not (library_entity db parent) -> Some parent
| _ -> None

let page_summary decrypt_title db eid =
let uuid = uuid_for_eid db eid in
let title = entity_title decrypt_title db eid in
Expand All @@ -425,6 +440,17 @@ let page_summary decrypt_title db eid =
else None
| _ -> None

let namespace_breadcrumbs decrypt_title db eid =
let rec loop seen eid ancestors =
match namespace_parent db eid with
| Some parent when not (List.mem parent seen) && value db parent "block/name" <> None ->
(match page_summary decrypt_title db parent with
| Some page -> loop (parent :: seen) parent (page :: ancestors)
| None -> ancestors)
| _ -> ancestors
in
loop [eid] eid []

let favorite_page_eid db =
match
List.of_seq
Expand Down Expand Up @@ -672,6 +698,14 @@ let tag_available_for_completion db eid =
])
| _ -> true

let search_page_tags decrypt_title db eid =
if entity_is_instance_of db eid "logseq.class/Tag" then []
else
tag_summaries decrypt_title db eid (fun tag ->
tag_available_for_completion db tag
&& value db tag "logseq.property.class/hide-from-node" <> Some (Ds.Bool true)
&& not (page_is_hidden db tag))

let tag_last_used db eid =
List.fold_left
(fun latest (datom : Ds.datom) -> max latest datom.tx)
Expand Down Expand Up @@ -711,26 +745,35 @@ let node_is_property db uuid =

let unique_named_uuid require_tag db name =
let key = String.lowercase_ascii (S.trim name) in
let index = if Ds.Schema.schema_attr_is_avet_accessible db.Ds.schema "block/name"
then Ds.Avet else Ds.Aevt in
let named name = Ds.Db.datoms db index ~a:"block/name" ~v:(Ds.String name) () in
if key = "" then None
else if not require_tag && String.contains key '/' then (
let rec resolve parent = function
| [] -> Option.bind parent (uuid_for_eid db)
| name :: rest ->
let matches = Ds.Db.datoms db Ds.Avet ~a:"block/name" ~v:(Ds.String name) ()
| part :: rest ->
let name = S.trim part in
let matches = named name
|> Seq.filter (fun (d : Ds.datom) -> not (page_is_hidden db d.e)
&& ref_eids db d.e "block/parent" = Option.to_list parent)
&& namespace_parent db d.e = parent)
|> List.of_seq in
match matches with [d] -> resolve (Some d.Ds.e) rest | _ -> None in
resolve None (String.split_on_char '/' key))
else (
let matches =
List.of_seq (Ds.Db.datoms db Ds.Aevt ~a:"block/name" ~v:(Ds.String key) ())
List.of_seq (named key)
|> List.map (fun (datom : Ds.datom) -> datom.e)
|> List.filter (fun eid ->
(not require_tag)
|| (entity_is_instance_of db eid "logseq.class/Tag"
&& tag_available_for_completion db eid))
not (page_is_hidden db eid)
&& (not require_tag || (entity_is_instance_of db eid "logseq.class/Tag"
&& tag_available_for_completion db eid)))
in
(* Prefer an unqualified page when a namespace also has this leaf name. *)
let matches = if require_tag then matches else
match List.filter (fun eid -> namespace_parent db eid = None) matches with
| [] -> matches
| roots -> roots in
match matches with
| [ eid ] -> uuid_for_eid db eid
| _ -> None)
Expand All @@ -757,13 +800,17 @@ let normalize_title_text create_tag db uuid title =
, entity_summaries (fun value -> Ok value) db eid "block/tags" )
| None -> ([], [])
in
let live = function
| Some uuid as found when Option.exists (fun eid -> not (recycled db eid))
(Ds.entid db "block/uuid" (Ds.Uuid uuid)) -> found
| _ -> None in
Ref_text.to_ids
(fun name ->
match known_title (refs @ tags) name with
match live (known_title (refs @ tags) name) with
| Some uuid -> Some uuid
| None -> unique_named_uuid false db name)
(fun name ->
match known_title tags name with
match live (known_title tags name) with
| Some uuid -> Some uuid
| None ->
(match unique_named_uuid true db name with
Expand Down
12 changes: 12 additions & 0 deletions shared/src/logseq/core/graph_read.mli
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ val visible_tag_summaries :
Datascript.db ->
int ->
Cache_model.entity_summary list
val search_page_tags :
(string -> (string, string) result) ->
Datascript.db ->
int ->
Cache_model.entity_summary list
val breadcrumbs :
(string -> (string, string) result) ->
Datascript.db ->
Expand All @@ -56,11 +61,18 @@ val block :
int ->
Cache_model.block option
val page_is_hidden : Datascript.db -> int -> bool
val namespace_children : Datascript.db -> int -> int Seq.t
val namespace_parent : Datascript.db -> int -> int option
val page_summary :
(string -> (string, string) result) ->
Datascript.db ->
int ->
Cache_model.entity_summary option
val namespace_breadcrumbs :
(string -> (string, string) result) ->
Datascript.db ->
int ->
Cache_model.entity_summary list
val favorite_page_eid : Datascript.db -> int option
val recycle_page_eid : Datascript.db -> int option
val last_order : Datascript.db -> string -> int -> string option
Expand Down
10 changes: 7 additions & 3 deletions shared/src/logseq/core/graph_runtime.ml
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,16 @@ let confirmed_operation confirmed server_t _authoritative

let stored_transaction runtime database (operation : Ops.pending_operation) =
let recompile = operation.base_t <> (state runtime).server_t &&
match operation.intent with Ops.Add_comment _ | Ops.Set_reaction _ -> true | _ -> false in
match operation.intent, operation.state with
| Ops.Add_comment _, _ | Ops.Set_reaction _, _ -> true
| Ops.Delete_page _, Ops.Accepted _ -> false
| Ops.Delete_page _, _ -> true
| _ -> false in
match Graph_sqlite.pending_tx runtime.path operation.operation_id with
| Some (tx, _) when not recompile -> Ok tx
| _ ->
(* Discussion writes depend on the current thread and actor's reactions.
Other operations retain their resolved transaction during reconciliation. *)
(* Re-resolve discussion writes and pending page deletions when the graph
changes. In particular, unlink references from the current titles. *)
let ( let* ) = Result.bind in
let* () =
if operation.base_t <> (state runtime).server_t && not (Ops.safe_to_rebase operation.intent) then
Expand Down
4 changes: 2 additions & 2 deletions shared/src/logseq/core/graph_sqlite.ml
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ let search_query path sql binds =

(* Root and tail identify the persisted graph without reading index nodes.
Pending intents identify the optimistic projection layered on that graph.
Bump the version when row eligibility changes, even if the schema does not. *)
Bump the version when row contents or eligibility change. *)
let search_source_version path =
with_app_db path (fun connection ->
let roots = query connection
Expand All @@ -432,7 +432,7 @@ let search_source_version path =
(fun row -> (Db.column_text row 0, Db.column_int row 1,
Db.column_text row 2, Db.column_text row 3)) in
Some (Digest.to_hex (Digest.string
(Marshal.to_string ("search-index-v3", roots, pending) []))))
(Marshal.to_string ("search-index-v4", roots, pending) []))))

let search_version path =
with_search_db path (fun connection ->
Expand Down
Loading
Loading