Write the visit in Kernel TERMINATE event

Created on 20 January 2021, over 3 years ago
Updated 11 September 2023, about 1 year 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

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.
  • @admirlju opened merge request.
  • 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 about 1 year 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.

  • Status changed to Needs review about 1 year 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.

Production build 0.71.5 2024