Order and nesting not working
I installed twill using the php artisan twill:install basic-page-builder command. Seems that ordering and nesting is not working on the navigation.
10 Replies
Turns out twill uses ReorderNestedModuleItems job for nesting and my QUEUE_CONNECTION is database. Just needed to do php artisan queue:work
So basicaly reordering items is impossible without cron job executing queue? Is there a way to have working sortable items without need to have access to cron?
I've found a solution how to manage it when no access to cron:
web.php
Route::get('/jobs/run', function() { Artisan::call('queue:work', ['--stop-when-empty' => true]); });
resources/vendor/twill/partials/head.blade.php (add to <script>):
<script src="/jobs.js" defer></script>
public/jobs.js:
This will do the trick for small websites. This fetch can also be put on frontend to have cronless queue, but it's better to have PHP function that will control frequency, so it won't be executed on every single frontend site visit. Also it would be a good idea to make a check if jobs/run is executed from within site.
Even better solution in PHP that runs in background (needs exec
available and php-cli
on server):
If we want to use it in frontent we can add things like:
- lock file and lock file check
- timestamp check (we can do it using database or just filemtime) to control execution rateOr, for small page trees, you can use Laravel's
sync
queue driverBut is it running in the background or blocking request until jobs are done?
yes, but it's really fast on a small page tree. also this only applies to self nested modules. A regular module with reordering enabled doesn't require a job.
I understand, but I think most websites use at least second level nesting. Also if it's possible to do it by middleware and in background without any slowdown it seems to do be a quite good solution also for big websites, because it actually does what cron does. I will share full code when it's finished.
be mindful that at scale the operations need to happen sequentially, otherwise you're going to end up with a broken tree
it can be recomputed though, see https://github.com/lazychaser/laravel-nestedset?tab=readme-ov-file#checking-consistency
GitHub
GitHub - lazychaser/laravel-nestedset: Effective tree structures in...
Effective tree structures in Laravel 4-8. Contribute to lazychaser/laravel-nestedset development by creating an account on GitHub.
yes, most websites do, but not necessarily with self nested modules. we have built a ton of very large websites without using it
I've finished my middleware. Code below does nothing more than
artisan queue:work --stop-when-empty
and really not more that only once in the minimum given time span of seconds (flock does the trick) and really in the background (command is daemonized) so there is no slowdowns while browsing. Let me know if you think this has some flaws:
https://dev.to/ordigital/cronless-queuework-in-laravel-executed-in-background-2n01DEV Community
Cronless queue:work in Laravel executed in background
There are some approaches how to execute queue:work but I found them useless. Here is a solution for...