diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 2b72f5318..7de7056eb 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -30,7 +30,7 @@ protected function schedule(Schedule $schedule) // $schedule->command('inspire') // ->hourly(); - $schedule->call(new FindOutdatedThumbnails); + $schedule->call(new FindOutdatedThumbnails)->everyFiveMinutes(); Log::channel('scheduler')->debug("Finished scheduler"); } diff --git a/app/Http/Controllers/APIKillZoneController.php b/app/Http/Controllers/APIKillZoneController.php index 211176baa..c0fe37efe 100644 --- a/app/Http/Controllers/APIKillZoneController.php +++ b/app/Http/Controllers/APIKillZoneController.php @@ -73,6 +73,9 @@ function store(Request $request, DungeonRoute $dungeonroute) // Bulk insert KillZoneEnemy::insert($killZoneEnemies); + + // Touch the route so that the thumbnail gets updated + $dungeonroute->touch(); } $result = ['id' => $killZone->id, 'enemy_forces' => $dungeonroute->getEnemyForcesAttribute()]; @@ -102,6 +105,9 @@ function delete(Request $request, DungeonRoute $dungeonroute, KillZone $killzone // Refresh the killzones relation $dungeonroute->load('killzones'); + // Touch the route so that the thumbnail gets updated + $dungeonroute->touch(); + $result = ['result' => 'success', 'enemy_forces' => $dungeonroute->getEnemyForcesAttribute()]; } catch (\Exception $ex) { $result = response('Not found', Http::NOT_FOUND); diff --git a/app/Http/Controllers/APIRouteController.php b/app/Http/Controllers/APIRouteController.php index 9574e53ad..3602e0be7 100644 --- a/app/Http/Controllers/APIRouteController.php +++ b/app/Http/Controllers/APIRouteController.php @@ -66,6 +66,9 @@ function store(Request $request) // Bulk insert RouteVertex::insert($vertices); + + // Touch the route so that the thumbnail gets updated + $dungeonRoute->touch(); } $result = ['id' => $route->id]; @@ -82,15 +85,19 @@ function delete(Request $request) $route = Route::findOrFail($request->get('id')); // @TODO WTF why does $route->dungeonroute not work?? It will NOT load the relation despite everything being OK? - $dungeonroute = DungeonRoute::findOrFail($route->dungeon_route_id); + $dungeonRoute = DungeonRoute::findOrFail($route->dungeon_route_id); // If we're not the author, don't delete anything // @TODO handle this in a policy? - if ($dungeonroute->author_id !== Auth::user()->id && !Auth::user()->hasRole('admin')) { + if ($dungeonRoute->author_id !== Auth::user()->id && !Auth::user()->hasRole('admin')) { throw new Exception('Unauthorized'); } $route->delete(); $route->deleteVertices(); + + // Touch the route so that the thumbnail gets updated + $dungeonRoute->touch(); + $result = ['result' => 'success']; } catch (\Exception $ex) { $result = response('Not found', Http::NOT_FOUND); diff --git a/app/Logic/Scheduler/FindOutdatedThumbnails.php b/app/Logic/Scheduler/FindOutdatedThumbnails.php index 5023964af..b1f1dbca7 100644 --- a/app/Logic/Scheduler/FindOutdatedThumbnails.php +++ b/app/Logic/Scheduler/FindOutdatedThumbnails.php @@ -31,10 +31,13 @@ function __invoke() $updatedAt = Carbon::createFromTimeString($dungeonRoute->updated_at); $thumbnailUpdatedAt = Carbon::createFromTimeString($dungeonRoute->thumbnail_updated_at); - // If the route has been updated in the past 30 minutes... - if ($updatedAt->addMinute(30)->isPast() && - // Updated at is greater than the thumbnail updated at (don't keep updating thumbnails.. - $updatedAt->greaterThan($thumbnailUpdatedAt)) { + if ((// Updated at is greater than the thumbnail updated at (don't keep updating thumbnails..) + $updatedAt->greaterThan($thumbnailUpdatedAt) && + // If the route has been updated in the past x minutes... + $updatedAt->addMinute(config('keystoneguru.thumbnail_refresh_min'))->isPast()) + || + // Update every month regardless + $updatedAt->addMonth(1)->isPast()) { if (!$this->isJobQueuedForModel('App\Jobs\ProcessRouteFloorThumbnail', $dungeonRoute)) { Log::channel('scheduler')->debug(sprintf('Queueing job for route %s (%s floors)', $dungeonRoute->public_key, $dungeonRoute->dungeon->floors->count())); diff --git a/app/Models/DungeonRoute.php b/app/Models/DungeonRoute.php index e4d6fa3a2..f888081e6 100644 --- a/app/Models/DungeonRoute.php +++ b/app/Models/DungeonRoute.php @@ -78,23 +78,6 @@ public function getRouteKeyName() return 'public_key'; } - /** - * @return string Generates a random public key that is displayed to the user in the URL. - */ - public static function generateRandomPublicKey() - { - do { - $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $charactersLength = strlen($characters); - $newKey = ''; - for ($i = 0; $i < 7; $i++) { - $newKey .= $characters[rand(0, $charactersLength - 1)]; - } - } while (DungeonRoute::all()->where('public_key', '=', $newKey)->count() > 0); - - return $newKey; - } - /** * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ @@ -529,6 +512,8 @@ public function isFavoritedByCurrentUser() return $result; } + + /** * @param null $user * @return bool @@ -543,6 +528,23 @@ public function isOwnedByUser($user = null) return $user !== null && $this->author_id === $user->id; } + /** + * @return string Generates a random public key that is displayed to the user in the URL. + */ + public static function generateRandomPublicKey() + { + do { + $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $newKey = ''; + for ($i = 0; $i < 7; $i++) { + $newKey .= $characters[rand(0, $charactersLength - 1)]; + } + } while (DungeonRoute::all()->where('public_key', '=', $newKey)->count() > 0); + + return $newKey; + } + public static function boot() { parent::boot(); diff --git a/composer.lock b/composer.lock index f71667035..baafeaa27 100644 --- a/composer.lock +++ b/composer.lock @@ -1413,16 +1413,16 @@ }, { "name": "jaybizzle/crawler-detect", - "version": "v1.2.74", + "version": "v1.2.75", "source": { "type": "git", "url": "https://github.com/JayBizzle/Crawler-Detect.git", - "reference": "e5fbc685383a4b8f49183b3a646b193491cc14c5" + "reference": "50e06c81bea8a9c443708be496868ccb55bdd396" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/JayBizzle/Crawler-Detect/zipball/e5fbc685383a4b8f49183b3a646b193491cc14c5", - "reference": "e5fbc685383a4b8f49183b3a646b193491cc14c5", + "url": "https://api.github.com/repos/JayBizzle/Crawler-Detect/zipball/50e06c81bea8a9c443708be496868ccb55bdd396", + "reference": "50e06c81bea8a9c443708be496868ccb55bdd396", "shasum": "" }, "require": { @@ -1458,7 +1458,7 @@ "crawlerdetect", "php crawler detect" ], - "time": "2018-11-21T20:56:45+00:00" + "time": "2018-12-10T19:38:45+00:00" }, { "name": "jenssegers/agent", diff --git a/config/keystoneguru.php b/config/keystoneguru.php index 21fce5f5a..908bf6b0f 100644 --- a/config/keystoneguru.php +++ b/config/keystoneguru.php @@ -51,7 +51,7 @@ 'view_time_threshold_mins' => 30, /** - * The amount of time to give the route thumbnail processor to complete its processing. + * The amount of time in minutes that must pass before a thumbnail is generated again from a changed dungeon route. */ - 'route_thumbnail_virtual_time_budget' => 10000 + 'thumbnail_refresh_min' => 30 ]; \ No newline at end of file diff --git a/package.json b/package.json index 700f12a45..c57946d82 100644 --- a/package.json +++ b/package.json @@ -16,8 +16,9 @@ "dependencies": { "@fortawesome/fontawesome-free": "^5.6.0", "ajv": "^6.6.1", + "alpha-shape": "^1.0.0", "bootstrap": "^4.1.3", - "bootstrap-select": "^1.13.3", + "bootstrap-select": "^1.13.4", "bootswatch": "^4.1.3", "color-interpolate": "^1.0.4", "cross-env": "^5.2.0",