mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 15:07:49 +00:00
Move current_image caching to plugins
This commit is contained in:
parent
6bfd9a2d8b
commit
4aa67ce02d
6 changed files with 18 additions and 18 deletions
|
|
@ -3,7 +3,7 @@
|
|||
namespace App\Jobs;
|
||||
|
||||
use App\Models\Device;
|
||||
use App\Models\PlaylistItem;
|
||||
use App\Models\Plugin;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Spatie\Browsershot\Browsershot;
|
||||
|
|
@ -62,8 +62,8 @@ class CommonFunctions
|
|||
public static function cleanupFolder(): void
|
||||
{
|
||||
$activeDeviceImageUuids = Device::pluck('current_screen_image')->filter()->toArray();
|
||||
$activePlaylistImageUuids = PlaylistItem::pluck('current_image')->filter()->toArray();
|
||||
$activeImageUuids = array_merge($activeDeviceImageUuids, $activePlaylistImageUuids);
|
||||
$activePluginImageUuids = Plugin::pluck('current_image')->filter()->toArray();
|
||||
$activeImageUuids = array_merge($activeDeviceImageUuids, $activePluginImageUuids);
|
||||
|
||||
$files = Storage::disk('public')->files('/images/generated/');
|
||||
foreach ($files as $file) {
|
||||
|
|
|
|||
|
|
@ -2,14 +2,14 @@
|
|||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\PlaylistItem;
|
||||
use App\Models\Plugin;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class GeneratePlaylistItemJob implements ShouldQueue
|
||||
class GeneratePluginJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ class GeneratePlaylistItemJob implements ShouldQueue
|
|||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly int $playlistItemId,
|
||||
private readonly int $pluginId,
|
||||
private readonly string $markup
|
||||
) {}
|
||||
|
||||
|
|
@ -28,8 +28,8 @@ class GeneratePlaylistItemJob implements ShouldQueue
|
|||
{
|
||||
$newImageUuid = CommonFunctions::generateImage($this->markup);
|
||||
|
||||
PlaylistItem::find($this->playlistItemId)->update(['current_image' => $newImageUuid]);
|
||||
\Log::info("Playlist item $this->playlistItemId: updated with new image: $newImageUuid");
|
||||
Plugin::find($this->pluginId)->update(['current_image' => $newImageUuid]);
|
||||
\Log::info("Plugin $this->pluginId: updated with new image: $newImageUuid");
|
||||
|
||||
CommonFunctions::cleanupFolder();
|
||||
}
|
||||
|
|
@ -15,7 +15,6 @@ class PlaylistItem extends Model
|
|||
protected $casts = [
|
||||
'is_active' => 'boolean',
|
||||
'last_displayed_at' => 'datetime',
|
||||
'current_image' => 'string',
|
||||
];
|
||||
|
||||
public function playlist(): BelongsTo
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ class Plugin extends Model
|
|||
'data_payload' => 'json',
|
||||
'data_payload_updated_at' => 'datetime',
|
||||
'is_native' => 'boolean',
|
||||
'current_image' => 'string',
|
||||
];
|
||||
|
||||
protected static function boot()
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ return new class extends Migration
|
|||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('playlist_items', function (Blueprint $table) {
|
||||
$table->string('current_image')->nullable()->after('is_active');
|
||||
Schema::table('plugins', function (Blueprint $table) {
|
||||
$table->string('current_image')->nullable()->after('data_payload_updated_at');
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ return new class extends Migration
|
|||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('playlist_items', function (Blueprint $table) {
|
||||
Schema::table('plugins', function (Blueprint $table) {
|
||||
$table->dropColumn('current_image');
|
||||
});
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
use App\Jobs\GenerateScreenJob;
|
||||
use App\Jobs\GeneratePlaylistItemJob;
|
||||
use App\Jobs\GeneratePluginJob;
|
||||
use App\Models\Device;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
|
|
@ -55,7 +55,7 @@ Route::get('/display', function (Request $request) {
|
|||
$plugin = $nextPlaylistItem->plugin;
|
||||
|
||||
// Check and update stale data if needed
|
||||
if ($plugin->isDataStale() || $nextPlaylistItem->last_displayed_at == null) {
|
||||
if ($plugin->isDataStale() || $plugin->current_image == null) {
|
||||
$plugin->updateDataPayload();
|
||||
|
||||
if ($plugin->render_markup) {
|
||||
|
|
@ -64,16 +64,16 @@ Route::get('/display', function (Request $request) {
|
|||
$markup = view($plugin->render_markup_view, ['data' => $plugin->data_payload])->render();
|
||||
}
|
||||
|
||||
GeneratePlaylistItemJob::dispatchSync($nextPlaylistItem->id, $markup);
|
||||
GeneratePluginJob::dispatchSync($plugin->id, $markup);
|
||||
}
|
||||
}
|
||||
|
||||
$nextPlaylistItem->refresh();
|
||||
$plugin->refresh();
|
||||
|
||||
if ($nextPlaylistItem->current_image != null)
|
||||
if ($plugin->current_image != null)
|
||||
{
|
||||
$nextPlaylistItem->update(['last_displayed_at' => now()]);
|
||||
$device->update(['current_screen_image' => $nextPlaylistItem->current_image]);
|
||||
$device->update(['current_screen_image' => $plugin->current_image]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue