codestudiohq / laravel-totem

Manage Your Laravel Schedule From A Web Dashboard
MIT License
1.78k stars 224 forks source link

Totem task_frequencies queries present in every request #301

Closed s1rc closed 3 years ago

s1rc commented 3 years ago

Every request made outside of Totem routes still has totem queries such as:

select
  *
from
  `totem_task_frequencies`
where
  `totem_task_frequencies`.`task_id` = 1
  and `totem_task_frequencies`.`task_id` is not null

and

select
  *
from
  `totem_frequency_parameters`
where
  `totem_frequency_parameters`.`frequency_id` in (1)

Is there a reason these queries and cache hits are running on all requests?

o-kima commented 3 years ago

what cache driver do you use?

s1rc commented 3 years ago

Redis.

o-kima commented 3 years ago

This happens as totem register his task to the scheduler in every app bootstrap, and not only in Console Kernel. Here is my Pull Request for this.

o-kima commented 3 years ago

Added new PR for that specific frequencies query https://github.com/codestudiohq/laravel-totem/pull/302

s1rc commented 3 years ago

@o-kima awesome thank you. Hopefully your PRs can be reviewed soon.

qschmick commented 3 years ago

@s1rc New release with update from @o-kima https://github.com/codestudiohq/laravel-totem/releases/tag/v8.3.0

s1rc commented 3 years ago

@qschmick thank you!

Testing this out, I see the Redis cache hits on every request. This is more ideal than querying the DB, is there a way to register the task in only the console kernel?

o-kima commented 3 years ago

Please add more details like what cache key it search and where it occurs in the flow. I just retested it in my app, listening to CacheHit|CacheMissed, no requests found in HTTP kernel.

Fixed at commit https://github.com/codestudiohq/laravel-totem/pull/299/commits/65c8e3d3e6eb2cf22c267f2388755ae587f709da

s1rc commented 3 years ago

Looking at Telescope, even on requests with no queries aside from session these are run:

Edit: I added a listener to EventServiceProvider for Illuminate\Cache\Events\CacheHit in case Telescope was mis-reporting. Both those are returning hits from every request.