Skip to content

Advanced query with :current-page return the same results with different values #4156

Closed

Description

@zivlinn

What happened?

Advanced query with :current-page on macOS/iOS desktop app return wrong results when switching different pages

Reproduce the Bug

  1. In current day journal page, eg: Feb 8th, 2022, create 2 TODO:
    image

  2. Go to page test-tag-A, add advanced query script from All todos tagged using current page,
    image

get the result :
image

  1. Go to page test-tag-B, add advanced query script from All todos tagged using current page,
    image

get the result :
image

The advanced query result in test-tag-B is wrong

Expected Behavior

Expected query result in page test-tag-B return TODOs with tag test-tag-B

Screenshots

Screenshots is added in Reproduce the Bug step.

Desktop Platform Information

  • OS: macOS 10.15.7
  • Browser: macOS desk top app
  • Version: 0.5.9

Mobile Platform Information

  • Device: [iPhone8]
  • OS: [iOS 14.4.2]
  • Browser [iOS app]
  • Version [0.5.9]

Additional Context

No response

Activity

  1. ondrejpales commented on Jul 18, 2022

    @ondrejpales

    I can confirm that I also encounter this issue. It happens in MacOS desktop app, Windows desktop app as well as in mobile app on iOS.

    The :current-page variable always remembers the first page it was used on (either it is somehow getting cached or it stops being updated after it gets initialized or used for the first time). Re-indexing the graph resets the variable but when it is used for the first time after re-indexing, it again keeps remembering the first page it was used on until next re-index.

    My use case:
    I have bunch of pages representing team members. On each of these pages there is this query - it's intention is to display tasks referencing (being assigned to) the particular person:

    #+BEGIN_QUERY
    {:title [:h3 "Taks mentioning this person"]
     :query [:find (pull ?b [*])
             :in $ ?currentpage
             :where
             (page-ref ?b ?currentpage)
             (task ?b #{"NOW" "LATER" "TODO" "DOING"})
             (or
                [?b :block/scheduled ?d]
                [?b :block/deadline ?d])
             ]
     :result-transform  (fn [result]
                                  (sort-by  (fn [d] 
                                  (get d :block/deadline) ) result ))
     :inputs [:current-page]}
    #+END_QUERY
    

    When I open the app and access John's page, the query correctly shows John's tasks. But when I then access Paul's page, it shows John's tasks (and continues showing John's tasks on all the persons' pages).

    If I then re-index and go to Paul's page, it now correctly shows Paul's tasks. But when I then go to John's page, it still shows Paul's tasks and continues to do so until next re-index.

    The issue is not limited to queries involving tasks. I was able to reproduce it with a different query involving the :current-page variable.

    Hope this helps to determine the cause and fix it as it makes the queries using :current-page unusable at all.

  2. atfornes commented on Oct 20, 2022

    @atfornes

    This also happens in Linux, so it is not a macOS/iOS problem

    I guess it is related to cached query results, as If I change the :title of the query, it recalculates the query with the expected results.

  3. atfornes commented on Oct 20, 2022

    @atfornes

    A workaround is to use the current page as part of the title of the query. This way, logseq knows they are different queries and calculate them independently.

    Using templates makes it easy! the following query would work to list open tasks of current page (as it will add the name of the page to the title of the query:

    ## Page's tasks
    template:: Page's Tasks
    template-including-parent:: false
    
    #+BEGIN_QUERY
    {:title "🔨 TASKS <% current page %>"
     :query [:find (pull ?b [*])
             :in $ ?tag
             :where
              [?b :block/marker ?marker]
              [(contains? #{"TODO" "DOING" "NOW" "LATER" "WAITING"} ?marker)]
             (page-ref ?b ?tag)]
     :inputs [:current-page]
     :result-transform (fn [result]
                                 (sort-by (fn [h]
                                       (get h :block/priority "Z")) result))
     :collapsed? false
    :breadcrumb-show? false}
    #+END_QUERY
    
  4. danilofaria commented on Dec 4, 2022

    @danilofaria

    I just stumbled upon this issue and it was pretty confusing! I am also on a mac and I was trying to reuse a query by referencing the block where the query is defined and using :current-page, but the query always shows the result of the first time it is run.
    I don't like the workaround of having to define a template that gives a different title to each query, because then I will still have to duplicate the query many times (each time the template is instantiated) and it defeats the purpose of my strategy to only define the query in one place.

  5. kerim commented on Dec 28, 2022

    @kerim

    This problem has been driving me crazy for months! I use :current-page in a frequently used template, and couldn't understand why I have to do a full re-index every time I create a new page with the template. I hope this can be fixed. I'll try the workaround in the meantime!

    UPDATE: workaround seems to do the trick!

  6. mpj commented on Dec 31, 2022

    @mpj

    God, this threw me out into a deep end, what a nasty subtle one, I thought I was going insane. The workaround works, but incredibly unintuitive.

  7. added
    :type/bug
    on Jan 9, 2023
  8. danilofaria commented on Jan 10, 2023

    @danilofaria

    People keep on bumping into this issue. This was just posted on Discuss. I also keep on seeing it come up on Discord. @logseq-cldwalker it might be a good idea to prioritize it.

  9. changed the title [-]Advanced query with `:current-page` on macOS/iOS desktop app return wrong results when switching different pages[/-] [+]Advanced query with :current-page return the same results with different values[/+] on Jan 10, 2023
  10. self-assigned this
    on Jan 12, 2023
  11. cnrpman commented on Jan 12, 2023

    @cnrpman
    Collaborator

    @danilofaria
    The current behavior of :current-page is "The current page of the main editing window", but with a cache issue (and fixed by #8263 thanks @oraluben !)
    And there are another kind of report like #6528
    They are expecting something like "The page that the query stored"?
    Also wonder if there are users using this "The current page of the main editing window" as a trait (which fits the name :current-page) and the change of behavior would break the assumption.

  12. oraluben commented on Jan 12, 2023

    @oraluben
    Contributor

    They are expecting something like "The page that the query stored"?

    This makes much more sense. The content of one page should be the same when it's embedded and not.
    (and I think no one should expect the opposite!)

    Edit: looks like a lot of people do rely on the current behavior🤔

  13. bendyorke commented on Jan 12, 2023

    @bendyorke
    Contributor

    I've just submitted #8330 which proposes another custom input, :query-page, that indeed will be the page the query is stored on.

    Hopefully having them live alongside each-other in the documentation will make it clear the difference and everyone get's both of best worlds :)

  14. danilofaria commented on Jan 12, 2023

    @danilofaria

    I think it would be extremely useful to be able to take a block reference of a query and paste it in other places and the results change based on the current page where the query is being run.

    This is the current behavior, except for this caching issue that shows one of the results only (not necessarily the result from the original page).

    So fixing the caching issue and considering :current-page the page where the query is shown (not where it is stored) IMO is the expected behavior (and the current behavior too).

    Adding a new custom input :query-page as suggested above also sounds good, as this would allow both things to be done.

  15. moved this from 🗄 Backlog to ✔ DONE in :Logseq/Issue-Trackeron Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

:type/bugcan-be-reproducedquery

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions