Last edited blocks from non-journal pages

Hi there,
I give in! After two days of trying, I’m begging to help.

What I’m trying to do: using advanced query

  1. to pull all blocks from all pages, exluding Journals,
  2. in one table, sorted by last updated,
  3. to show only last 25 blocks (not all hundreds of them)
  4. show icon:: property in front of each line (block name)

Looks like on the screen:
Query all blocks

Now I’m even doubt it’s possible at all, but if someone have ideas or can help I would appreciate

1 Like

Welcome. Just a few things:

First of all, huge thanks! It moves me forward. What I see now (query code below):

  • Point # 1 partly solved. No Journals. Nevertheless, I discover that from one tread of blocks table shows only one block – last updated – and seems that if parent-block has been updated than further child’s updates will not be displayed in table. Interesting. I’ll look over more here.
  • Point # 2 solved.
  • Point # 3 solved.
  • Point # 4 canceled: no point to have icon for blocks.

! One more point (# 5) needed: how in the table view to get column “updated-at” where the date and time of last update will be shown?

#+BEGIN_QUERY
{:title [:h2 “Recent changes”]
:query [:find (pull ?b [*])
:where
[?b :block/page ?p]
(not [?p :block/journal? true])
]
:result-transform (fn [result] (take 15
(sort-by (comp - (fn [h]
(get h :block/updated-at))) result)) )
}
#+END_QUERY

Try something like (assoc block :block/updated-at datetime) (see Result transform conditional).

If you want each block to show up regardless of whether it is the child of a different result, there is an option you can add.
:remove-block-children? false
https://docs.logseq.com/#/page/advanced%20queries/block/remove-block-children%3F

PS. Also @mentaloid we can actually use [?p :block/journal? false] instead of added a not clause :wink:

Except in cases that instead of having :block/journal? false they simply omit :block/journal?

Thanks! One step further down this path ))
After adding :remove-block-children? false Point #1 seems to be solved.

But, now column “updated-at” disappeared from the table.
I have now only one column:

Instead of original vision:
Query all blocks

But anyway, thanks, its something closer to the point.

Updated :: Seems I found the answer, will test today and give you know

Well, I couldn’t find any working way to use it, sorry to say.
Was trying to add (assoc block :block/updated-at datetime) line somewhere after :result-transform, but any combination seems to broke the original working functions.

Updated!
mentaloid, Siferiax thanks for your help! Huge relief.

Right now I have all original functionality I’d asked for. Plus one addition: to exclude certain page search. I’ll put full code below in case of someone interested.

1. The query itself

#+BEGIN_QUERY
{:title [:h1 “Last updated blocks”]
:query [:find (pull ?b [*])
:where
[?b :block/page ?p]
(not [?p :block/journal? true])
(not [?b :block/path-refs [:block/name “menu”]])
]
:group-by-page? false
:remove-block-children? false
:result-transform (fn [result] (take 25
(sort-by (comp - (fn [h]
(get h :block/updated-at))) result)))
}
#+END_QUERY

2. Additon to custom.css (in vault folder)
to limit length of the block name displayed therefore not hidding “updated-ad” column.
Original source is here, answered by mentaloid

.custom-query-results td.whitespace-nowrap div {
display: inline-block;
overflow: hidden;
text-overflow: ellipsis;
max-width: 62ch;
}

1 Like

Ah! You’re right :disappointed_relieved: stupid inconsistencies.

As @mentaloid pointed out, might not always work due to inconsistency of Logseq actually adding this attribute to page :expressionless:
So if you run into issues you might want to switch this back to (not [?p :block/journal? true])