Merge pull request #52 from imlonghao/fix/cache

refresh servers cache on due date changed and one other change
This commit is contained in:
corbpie 2022-07-05 00:01:19 +10:00 committed by GitHub
commit a752e2ab60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -92,6 +92,7 @@ class Home extends Model
{
$pricing = new Pricing();
$count = $altered_due_soon = 0;
$server_due_date_changed = false;
foreach ($due_soon as $service) {
if (Carbon::createFromFormat('Y-m-d', $service->next_due_date)->isPast()) {
$months = $pricing->termAsMonths($service->term);//Get months for term to update the next due date to
@ -101,12 +102,20 @@ class Home extends Model
->update(['next_due_date' => $new_due_date]);
$due_soon[$count]->next_due_date = $new_due_date;//Update array being sent to view
$altered_due_soon = 1;
if ($service->service_type === 1) {
$server_due_date_changed = true;
Server::serverSpecificCacheForget($service->service_id);
}
} else {
break;//Break because if this date isnt past than the ones after it in the loop wont be either
}
$count++;
}
if ($server_due_date_changed) {
Server::serverRelatedCacheForget();
}
if ($altered_due_soon === 1) {//Made changes to due soon so re-write it
Cache::put('due_soon', $due_soon);
}

View File

@ -79,7 +79,7 @@
<td class="text-nowrap">{{ $server->provider_name }}</td>
<td class="text-nowrap">{{ $server->price }} {{$server->currency}} {{\App\Process::paymentTermIntToString($server->term)}}</td>
<td class="text-nowrap">
{{now()->diffInDays(Carbon\Carbon::parse($server->next_due_date))}}
{{now()->diffInDays(Carbon\Carbon::parse($server->next_due_date), false)}}
<small>days</small></td>
<td class="text-nowrap"> {{ $server->owned_since }}</td>
<td class="text-nowrap">
@ -187,7 +187,8 @@
@endforeach
@else
<tr>
<td class="px-4 py-2 border text-red-500" colspan="3">No non-active servers found.</td>
<td class="px-4 py-2 border text-red-500" colspan="3">No non-active servers found.
</td>
</tr>
@endif
</tbody>