Write the visit in Kernel TERMINATE event

Created on 20 January 2021, over 4 years ago
Updated 8 September 2023, almost 2 years ago

Problem/Motivation

There was a discussion here about the caching which was too hardly disabled for all view modes. This gave us the thinking of using the javascript, but now I think the best way to store the visit is in Kernel TERMINATE event. This way the response is already sent to browser so there is no lag in load time, also there is no additional javascript needed.

Proposed resolution

Move the logic of saving the visited item from hook_entity_view to Event subscriber which will be listening to the Kernel TERMINATE event.

Feature request
Status

Needs review

Version

1.0

Component

Code

Created by

🇸🇮Slovenia boshtian

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • Pipeline finished with Success
    almost 2 years ago
    #18672
  • Pipeline finished with Success
    almost 2 years ago
    #18673
  • This was more work than expected. Since the patch fails to apply I coded it by hand. The thing is this patch worked only for entity types of Node, while the module is supposed to support any entity type, also implemented it using dependency injection. Fixed the tests and added doc comments.

  • There is also a similar fix in 📌 Disabled page caching Needs review but using a different event. That one adds content to a recently read table on KernelEvent::REQUEST, so they are added before the page is loaded to the client, I go a bit into details in comment #11.

  • Status changed to Needs work almost 2 years ago
  • Okay, so it looks like this will not work for anonymous users, at least not after the first session is created in recently_read_entity_view(). This happens because hook_entity_view() runs only when the view is not cached. So this will have to be moved somewhere else.

  • Pipeline finished with Success
    almost 2 years ago
    #19054
  • Status changed to Needs review almost 2 years ago
  • I moved the anonymous session check to an event subscriber, that runs on KernelEvents::REQUEST on priority 27. This way the session check for anonymous users gets done even if the page is already cached.

  • First commit to issue fork.
  • 🇸🇮Slovenia jernejmramor

    Hello,

    I've taken a look into this issue and rebased latest dev into it and fixed failing tests. So this is now ready to be re reviewed.

    However please note that this issue changes how the module works so I would recommend creating a new major release for it.
    In previous versions of this module and current dev branch, tracked entities are logged immediately when user navigates to a page where an entity needs to be tracked that will be done immediately and the block that comes with the module will display entity which we are currently on.

    In this issue this behavior changes. When user navigates to an entity which should get tracked then this entity won't appear in the recently read block as we are still currently viewing it. It will appear correctly after navigating to a different page.

    For example:
    Current dev: User navigates to /node/1. Block already displays /node/1 in recently read block.
    This issue: User navigates to /node/1. Block doesn't display /node/1 as read. User navigates to somewhere else where the block is still visible. /node/1 is now displayed in the block.

    I would prefer the module to work like it does in this issue, as it only display which entities we read after we navigated away from instead, of having entity tracked immediately.

    Leaving this in needs review as some changes were made since this was last worked on.

Production build 0.71.5 2024