diff --git a/database/migrations/2019_09_25_103421_update_task_results_duration_type.php b/database/migrations/2019_09_25_103421_update_task_results_duration_type.php
index eb07d72e..0c91404a 100644
--- a/database/migrations/2019_09_25_103421_update_task_results_duration_type.php
+++ b/database/migrations/2019_09_25_103421_update_task_results_duration_type.php
@@ -28,7 +28,7 @@ public function down()
}
/**
- * @param bool $toFloat
+ * @param bool $toFloat
*/
private function migrateDurationValues(bool $toFloat = true)
{
diff --git a/database/migrations/2022_03_14_120000_alter_task_results_table_add_index_on_created_at.php b/database/migrations/2022_03_14_120000_alter_task_results_table_add_index_on_created_at.php
new file mode 100644
index 00000000..b7b96278
--- /dev/null
+++ b/database/migrations/2022_03_14_120000_alter_task_results_table_add_index_on_created_at.php
@@ -0,0 +1,34 @@
+table(TOTEM_TABLE_PREFIX.'task_results', function (Blueprint $table) {
+ $table->index('created_at');
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::connection(TOTEM_DATABASE_CONNECTION)
+ ->table(TOTEM_TABLE_PREFIX.'task_results', function (Blueprint $table) {
+ $table->dropIndex('created_at');
+ });
+ }
+}
diff --git a/resources/views/tasks/view.blade.php b/resources/views/tasks/view.blade.php
index a30f96e1..7bb535da 100644
--- a/resources/views/tasks/view.blade.php
+++ b/resources/views/tasks/view.blade.php
@@ -55,7 +55,7 @@
Average Run Time
- {{$task->results->count() > 0 ? number_format( $task->results->sum('duration') / (1000 * $task->results->count()) , 2) : '0'}} seconds
+ {{$task->results()->count() > 0 ? number_format( $task->results()->sum('duration') / (1000 * $task->results()->count()) , 2) : '0'}} seconds
Next Run Schedule
diff --git a/src/Console/Commands/ListSchedule.php b/src/Console/Commands/ListSchedule.php
index 0be8fafb..2fda418f 100644
--- a/src/Console/Commands/ListSchedule.php
+++ b/src/Console/Commands/ListSchedule.php
@@ -32,7 +32,7 @@ class ListSchedule extends Command
/**
* Create a new command instance.
*
- * @param Schedule $schedule
+ * @param Schedule $schedule
* @return void
*/
public function __construct(Schedule $schedule)
diff --git a/src/Contracts/TaskInterface.php b/src/Contracts/TaskInterface.php
index d2b8efb7..e85cb72a 100644
--- a/src/Contracts/TaskInterface.php
+++ b/src/Contracts/TaskInterface.php
@@ -21,12 +21,14 @@ public function find($id);
/**
* Returns all tasks.
+ *
* @return \Illuminate\Database\Eloquent\Collection
*/
public function findAll();
/**
* Returns all active tasks.
+ *
* @return \Illuminate\Database\Eloquent\Collection
*/
public function findAllActive();
@@ -34,7 +36,7 @@ public function findAllActive();
/**
* Creates a new task with the given data.
*
- * @param array $input
+ * @param array $input
* @return \Studio\Totem\Task
*/
public function store(array $input);
@@ -42,7 +44,7 @@ public function store(array $input);
/**
* Updates the given task with the given data.
*
- * @param array $input
+ * @param array $input
* @param \Studio\Totem\Task $task
* @return \Studio\Totem\Task
*/
diff --git a/src/Events/Creating.php b/src/Events/Creating.php
index b179055d..53d0b6f8 100644
--- a/src/Events/Creating.php
+++ b/src/Events/Creating.php
@@ -21,7 +21,7 @@ class Creating implements ShouldBroadcast
/**
* Create a new event instance.
*
- * @param array $input
+ * @param array $input
*/
public function __construct(array $input)
{
diff --git a/src/Events/Deleted.php b/src/Events/Deleted.php
index 0b3d590a..51eefd5f 100644
--- a/src/Events/Deleted.php
+++ b/src/Events/Deleted.php
@@ -7,8 +7,8 @@ class Deleted extends Event
/**
* Create a new event instance.
*
- * @param array $input
- * @param Task $task
+ * @param array $input
+ * @param Task $task
*/
public function __construct()
{
diff --git a/src/Events/Executed.php b/src/Events/Executed.php
index 666b7c2a..a0eec41e 100644
--- a/src/Events/Executed.php
+++ b/src/Events/Executed.php
@@ -10,8 +10,8 @@ class Executed extends BroadcastingEvent
/**
* Executed constructor.
*
- * @param Task $task
- * @param string $started
+ * @param Task $task
+ * @param string $started
*/
public function __construct(Task $task, $started, $output)
{
diff --git a/src/Events/TaskEvent.php b/src/Events/TaskEvent.php
index c64c85af..4b88cdd0 100644
--- a/src/Events/TaskEvent.php
+++ b/src/Events/TaskEvent.php
@@ -18,7 +18,7 @@ class TaskEvent extends Event
/**
* Constructor.
*
- * @param Task $task
+ * @param Task $task
*/
public function __construct(Task $task)
{
diff --git a/src/Events/Updating.php b/src/Events/Updating.php
index 95ff3b8c..d53c9e8c 100644
--- a/src/Events/Updating.php
+++ b/src/Events/Updating.php
@@ -16,8 +16,8 @@ class Updating extends BroadcastingEvent
/**
* Create a new event instance.
*
- * @param array $input
- * @param Task $task
+ * @param array $input
+ * @param Task $task
*/
public function __construct(array $input, Task $task)
{
diff --git a/src/Http/Controllers/ActiveTasksController.php b/src/Http/Controllers/ActiveTasksController.php
index 2e93c1eb..779c181e 100644
--- a/src/Http/Controllers/ActiveTasksController.php
+++ b/src/Http/Controllers/ActiveTasksController.php
@@ -13,7 +13,7 @@ class ActiveTasksController extends Controller
private $tasks;
/**
- * @param TaskInterface $tasks
+ * @param TaskInterface $tasks
*/
public function __construct(TaskInterface $tasks)
{
diff --git a/src/Http/Controllers/ExecuteTasksController.php b/src/Http/Controllers/ExecuteTasksController.php
index 291d1e99..1b97e456 100644
--- a/src/Http/Controllers/ExecuteTasksController.php
+++ b/src/Http/Controllers/ExecuteTasksController.php
@@ -13,7 +13,7 @@ class ExecuteTasksController extends Controller
private $tasks;
/**
- * @param TaskInterface $tasks
+ * @param TaskInterface $tasks
*/
public function __construct(TaskInterface $tasks)
{
diff --git a/src/Http/Controllers/ExportTasksController.php b/src/Http/Controllers/ExportTasksController.php
index 3d4373dd..b9e22972 100644
--- a/src/Http/Controllers/ExportTasksController.php
+++ b/src/Http/Controllers/ExportTasksController.php
@@ -13,7 +13,8 @@ class ExportTasksController extends Controller
/**
* ExportTasksController constructor.
- * @param TaskInterface $tasks
+ *
+ * @param TaskInterface $tasks
*/
public function __construct(TaskInterface $tasks)
{
diff --git a/src/Http/Controllers/ImportTasksController.php b/src/Http/Controllers/ImportTasksController.php
index f6e44d3e..6bfa813b 100644
--- a/src/Http/Controllers/ImportTasksController.php
+++ b/src/Http/Controllers/ImportTasksController.php
@@ -14,7 +14,8 @@ class ImportTasksController extends Controller
/**
* ImportTasksController constructor.
- * @param TaskInterface $tasks
+ *
+ * @param TaskInterface $tasks
*/
public function __construct(TaskInterface $tasks)
{
@@ -25,7 +26,9 @@ public function __construct(TaskInterface $tasks)
/**
* Import tasks from a json file.
- * @param \Studio\Totem\Http\Requests\ImportRequest $request
+ *
+ * @param \Studio\Totem\Http\Requests\ImportRequest $request
+ *
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
public function index(ImportRequest $request)
diff --git a/src/Http/Controllers/TasksController.php b/src/Http/Controllers/TasksController.php
index 6e3e48f4..960d1208 100644
--- a/src/Http/Controllers/TasksController.php
+++ b/src/Http/Controllers/TasksController.php
@@ -18,7 +18,7 @@ class TasksController extends Controller
/**
* TasksController constructor.
*
- * @param TaskInterface $tasks
+ * @param TaskInterface $tasks
*/
public function __construct(TaskInterface $tasks)
{
@@ -45,6 +45,7 @@ public function index()
->when(request('q'), function (Builder $query) {
$query->where('description', 'LIKE', '%'.request('q').'%');
})
+ ->with('frequencies')
->paginate(20),
]);
}
@@ -71,7 +72,7 @@ public function create()
/**
* Store a newly created task in storage.
*
- * @param TaskRequest $request
+ * @param TaskRequest $request
* @return \Illuminate\Http\RedirectResponse
*/
public function store(TaskRequest $request)
@@ -119,7 +120,7 @@ public function edit(Task $task)
/**
* Update the specified task in storage.
*
- * @param TaskRequest $request
+ * @param TaskRequest $request
* @param $task
* @return \Illuminate\Http\RedirectResponse
*/
diff --git a/src/Http/Requests/ImportRequest.php b/src/Http/Requests/ImportRequest.php
index 6fb2a7dd..c5ffd34d 100644
--- a/src/Http/Requests/ImportRequest.php
+++ b/src/Http/Requests/ImportRequest.php
@@ -51,6 +51,7 @@ public function messages()
*
* @param array|mixed $keys
* @return array
+ *
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
public function all($keys = null)
@@ -68,6 +69,7 @@ public function all($keys = null)
* Get the validated data from the request.
*
* @return array
+ *
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
public function validated()
@@ -84,7 +86,7 @@ public function validated()
/**
* * Handle a failed validation attempt.
*
- * @param Validator $validator
+ * @param Validator $validator
*/
protected function failedValidation(Validator $validator)
{
diff --git a/src/Listeners/BuildCache.php b/src/Listeners/BuildCache.php
index c34c5368..5ba060d3 100644
--- a/src/Listeners/BuildCache.php
+++ b/src/Listeners/BuildCache.php
@@ -19,7 +19,7 @@ public function handle(Event $event)
/**
* Rebuild Cache.
*
- * @param Event $event
+ * @param Event $event
*/
protected function build(Event $event)
{
diff --git a/src/Listeners/BustCache.php b/src/Listeners/BustCache.php
index 12afda2d..13abf5e0 100644
--- a/src/Listeners/BustCache.php
+++ b/src/Listeners/BustCache.php
@@ -19,7 +19,7 @@ public function handle(Event $event)
/**
* Clear Cache.
*
- * @param Event $event
+ * @param Event $event
*/
protected function clear(Event $event)
{
diff --git a/src/Listeners/BustCacheImmediately.php b/src/Listeners/BustCacheImmediately.php
index 5f3f17b9..79652a67 100644
--- a/src/Listeners/BustCacheImmediately.php
+++ b/src/Listeners/BustCacheImmediately.php
@@ -15,7 +15,7 @@ class BustCacheImmediately
/**
* Create the event listener.
*
- * @param Container $app
+ * @param Container $app
*/
public function __construct(Container $app)
{
@@ -35,7 +35,7 @@ public function handle(Event $event)
/**
* Clear Cache.
*
- * @param Event $event
+ * @param Event $event
*/
protected function clear(Event $event)
{
diff --git a/src/Listeners/Listener.php b/src/Listeners/Listener.php
index db3fce85..52e685f4 100644
--- a/src/Listeners/Listener.php
+++ b/src/Listeners/Listener.php
@@ -21,8 +21,8 @@ class Listener implements ShouldQueue
/**
* Create the event listener.
*
- * @param Container $app
- * @param TaskInterface $tasks
+ * @param Container $app
+ * @param TaskInterface $tasks
*/
public function __construct(Container $app, TaskInterface $tasks)
{
diff --git a/src/Repositories/EloquentTaskRepository.php b/src/Repositories/EloquentTaskRepository.php
index 3fe9e899..bca6af65 100644
--- a/src/Repositories/EloquentTaskRepository.php
+++ b/src/Repositories/EloquentTaskRepository.php
@@ -44,7 +44,7 @@ public function builder(): Builder
/**
* Find a task by id.
*
- * @param int|Task $id
+ * @param int|Task $id
* @return int|Task
*/
public function find($id)
@@ -87,7 +87,7 @@ public function findAllActive()
/**
* Create a new task.
*
- * @param array $input
+ * @param array $input
* @return bool|Task
*/
public function store(array $input)
@@ -108,8 +108,8 @@ public function store(array $input)
/**
* Update the given task.
*
- * @param array $input
- * @param Task $task
+ * @param array $input
+ * @param Task $task
* @return bool|int|Task
*/
public function update(array $input, $task)
@@ -130,7 +130,7 @@ public function update(array $input, $task)
/**
* Delete the given task.
*
- * @param int|Task $id
+ * @param int|Task $id
* @return bool
*/
public function destroy($id)
diff --git a/src/Task.php b/src/Task.php
index 19b9bb93..79bc536f 100644
--- a/src/Task.php
+++ b/src/Task.php
@@ -74,8 +74,7 @@ public function getUpcomingAttribute()
/**
* Convert a string of command arguments and options to an array.
*
- * @param bool $console if true will convert arguments to non associative array
- *
+ * @param bool $console if true will convert arguments to non associative array
* @return array
*/
public function compileParameters($console = false)
@@ -193,18 +192,36 @@ public function autoCleanup()
{
if ($this->auto_cleanup_num > 0) {
if ($this->auto_cleanup_type === 'results') {
- $oldest_id = self::results()
+ $oldest_id = $this->results()
->orderBy('ran_at', 'desc')
->limit($this->auto_cleanup_num)
->get()
->min('id');
- self::results()
- ->where('id', '<', $oldest_id)
- ->delete();
+ do {
+ $rowsToDelete = $this->results()
+ ->where('id', '<', $oldest_id)
+ ->limit(50)
+ ->getQuery()
+ ->select('id')
+ ->pluck('id');
+
+ Result::query()
+ ->whereIn('id', $rowsToDelete)
+ ->delete();
+ } while ($rowsToDelete->count() > 0);
} else {
- self::results()
- ->where('ran_at', '<', Carbon::now()->subDays($this->auto_cleanup_num - 1))
- ->delete();
+ do {
+ $rowsToDelete = $this->results()
+ ->where('ran_at', '<', Carbon::now()->subDays($this->auto_cleanup_num - 1))
+ ->limit(50)
+ ->getQuery()
+ ->select('id')
+ ->pluck('id');
+
+ Result::query()
+ ->whereIn('id', $rowsToDelete)
+ ->delete();
+ } while ($rowsToDelete->count() > 0);
}
}
}
diff --git a/src/Totem.php b/src/Totem.php
index 82de81ee..6b9f6362 100644
--- a/src/Totem.php
+++ b/src/Totem.php
@@ -22,7 +22,6 @@ class Totem
* Determine if the given request can access the Totem dashboard.
*
* @param \Illuminate\Http\Request $request
- *
* @return bool
*/
public static function check($request)
@@ -35,8 +34,7 @@ public static function check($request)
/**
* Set the callback that should be used to authenticate Totem users.
*
- * @param \Closure $callback
- *
+ * @param Closure $callback
* @return static
*/
public static function auth(Closure $callback)
diff --git a/src/Traits/FrontendSortable.php b/src/Traits/FrontendSortable.php
index d24bd5d7..59823cf5 100644
--- a/src/Traits/FrontendSortable.php
+++ b/src/Traits/FrontendSortable.php
@@ -7,10 +7,9 @@
trait FrontendSortable
{
/**
- * @param \Illuminate\Database\Eloquent\Builder $builder
- * @param array $sortableColumns
- * @param array $defaultSort
- *
+ * @param \Illuminate\Database\Eloquent\Builder $builder
+ * @param array $sortableColumns
+ * @param array $defaultSort
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeSortableBy(Builder $builder, array $sortableColumns, array $defaultSort = ['name' => 'asc']): Builder
diff --git a/tests/Feature/ViewDashboardTest.php b/tests/Feature/ViewDashboardTest.php
index d9dd8b13..1edb8ba5 100644
--- a/tests/Feature/ViewDashboardTest.php
+++ b/tests/Feature/ViewDashboardTest.php
@@ -80,8 +80,8 @@ public function view_dashboard_multiple_tasks_with_multiple_results()
}
/**
- * @param int $task_count
- * @param int $result_count
+ * @param int $task_count
+ * @param int $result_count
* @return mixed
*/
private function _get_task_with_results($task_count = 1, $result_count = 1)