Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADVAPP-358] #555

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app-modules/alert/src/Observers/AlertObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public function created(Alert $alert): void
resolve(SubscriptionCreate::class)->handle($user, $alert->getSubscribable(), false);

Cache::tags([match ($alert->concern_type) {
app(Prospect::class)->getMorphClass() => "{user-{$user->getKey()}-prospect-alerts}",
app(Student::class)->getMorphClass() => "{user-{$user->getKey()}-student-alerts}",
app(Prospect::class)->getMorphClass() => "user-{$user->getKey()}-prospect-alerts",
app(Student::class)->getMorphClass() => "user-{$user->getKey()}-student-alerts",
}])->flush();
}

Expand All @@ -77,8 +77,8 @@ public function deleted(Alert $alert): void

if ($user) {
Cache::tags([match ($alert->concern_type) {
app(Prospect::class)->getMorphClass() => "{user-{$user->getKey()}-prospect-alerts}",
app(Student::class)->getMorphClass() => "{user-{$user->getKey()}-student-alerts}",
app(Prospect::class)->getMorphClass() => "user-{$user->getKey()}-prospect-alerts",
app(Student::class)->getMorphClass() => "user-{$user->getKey()}-student-alerts",
}])->flush();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function created(ApplicationSubmission $submission): void
if (! is_null($submission->author)) {
Cache::tags('{application-submission-count}')
->forget(
"{application-submission-count-{$submission->author->getKey()}}"
"application-submission-count-{$submission->author->getKey()}"
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function created(FormSubmission $submission): void
if (! is_null($submission->author)) {
Cache::tags('{form-submission-count}')
->forget(
"{form-submission-count-{$submission->author->getKey()}}"
"form-submission-count-{$submission->author->getKey()}"
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public function created(Subscription $subscription): void

if ($user) {
Cache::tags([match ($subscription->subscribable_type) {
app(Prospect::class)->getMorphClass() => "{user-{$user->getKey()}-prospect-subscriptions",
app(Student::class)->getMorphClass() => "{user-{$user->getKey()}-student-subscriptions",
app(Prospect::class)->getMorphClass() => "user-{$user->getKey()}-prospect-subscriptions",
app(Student::class)->getMorphClass() => "user-{$user->getKey()}-student-subscriptions",
}])->flush();
}
}
Expand All @@ -70,8 +70,8 @@ public function deleted(Subscription $subscription): void

if ($user) {
Cache::tags([match ($subscription->subscribable_type) {
app(Prospect::class)->getMorphClass() => "{user-{$user->getKey()}-prospect-subscriptions",
app(Student::class)->getMorphClass() => "{user-{$user->getKey()}-student-subscriptions",
app(Prospect::class)->getMorphClass() => "user-{$user->getKey()}-prospect-subscriptions",
app(Student::class)->getMorphClass() => "user-{$user->getKey()}-student-subscriptions",
}])->flush();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static function getNavigationItems(array $urlParameters = []): array
/** @var Prospect $ownerRecord */
$alertsCount = Cache::tags('{alert-count}')
->remember(
"{alert-count-{$ownerRecord->getKey()}}",
"alert-count-{$ownerRecord->getKey()}",
now()->addMinutes(5),
function () use ($ownerRecord): int {
return $ownerRecord->alerts()->status(AlertStatus::Active)->count();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public static function getNavigationItems(array $urlParameters = []): array
/** @var Prospect $ownerRecord */
$applicationSubmissionsCount = Cache::tags('{application-submission-count}')
->remember(
"{application-submission-count-{$ownerRecord->getKey()}}",
"application-submission-count-{$ownerRecord->getKey()}",
now()->addMinutes(5),
function () use ($ownerRecord): int {
return $ownerRecord->applicationSubmissions()->count();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public static function getNavigationItems(array $urlParameters = []): array
/** @var Prospect $ownerRecord */
$formSubmissionsCount = Cache::tags('{form-submission-count}')
->remember(
"{form-submission-count-{$ownerRecord->getKey()}}",
"form-submission-count-{$ownerRecord->getKey()}",
now()->addMinutes(5),
function () use ($ownerRecord): int {
return $ownerRecord->formSubmissions()->count();
Expand Down
12 changes: 6 additions & 6 deletions app-modules/prospect/src/Filament/Widgets/ProspectStats.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,21 @@ protected function getStats(): array
return [
Stat::make('Prospects', Number::abbreviate(
Cache::tags(['{prospects}'])
->remember('{prospects-count}', now()->addHour(), function (): int {
->remember('prospects-count', now()->addHour(), function (): int {
return Prospect::count();
}),
maxPrecision: 2,
)),
Stat::make('Subscriptions', Cache::tags(['{prospects}', "{user-{$user->getKey()}-prospect-subscriptions}"])
->remember("{user-{$user->getKey()}-prospect-subscriptions-count}", now()->addHour(), function () use ($user): int {
Stat::make('Subscriptions', Cache::tags(['{prospects}', "user-{$user->getKey()}-prospect-subscriptions"])
->remember("user-{$user->getKey()}-prospect-subscriptions-count", now()->addHour(), function () use ($user): int {
return $user->prospectSubscriptions()->count();
})),
Stat::make('Alerts', Cache::tags(['{prospects}', "{user-{$user->getKey()}-prospect-alerts}"])
->remember("{user-{$user->getKey()}-prospect-alerts-count}", now()->addHour(), function () use ($user): int {
Stat::make('Alerts', Cache::tags(['{prospects}', "user-{$user->getKey()}-prospect-alerts"])
->remember("user-{$user->getKey()}-prospect-alerts-count", now()->addHour(), function () use ($user): int {
return $user->prospectAlerts()->status(AlertStatus::Active)->count();
})),
Stat::make('Caseloads', Cache::tags(["{user-{$user->getKey()}-prospect-caseloads}"])
->remember("{user-{$user->getKey()}-prospect-caseloads-count}", now()->addHour(), function () use ($user): int {
->remember("user-{$user->getKey()}-prospect-caseloads-count", now()->addHour(), function () use ($user): int {
return $user->caseloads()->model(CaseloadModel::Prospect)->count();
})),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static function getNavigationItems(array $urlParameters = []): array
/** @var Student $ownerRecord */
$alertsCount = Cache::tags('{alert-count}')
->remember(
"{alert-count-{$ownerRecord->getKey()}}",
"alert-count-{$ownerRecord->getKey()}",
now()->addMinutes(5),
function () use ($ownerRecord): int {
return $ownerRecord->alerts()->status(AlertStatus::Active)->count();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public static function getNavigationItems(array $urlParameters = []): array
/** @var Student $ownerRecord */
$applicationSubmissionsCount = Cache::tags('{application-submission-count}')
->remember(
"{application-submission-count-{$ownerRecord->getKey()}}",
"application-submission-count-{$ownerRecord->getKey()}",
now()->addMinutes(5),
function () use ($ownerRecord): int {
return $ownerRecord->applicationSubmissions()->count();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public static function getNavigationItems(array $urlParameters = []): array
/** @var Prospect $ownerRecord */
$formSubmissionsCount = Cache::tags('{form-submission-count}')
->remember(
"{form-submission-count-{$ownerRecord->getKey()}}",
"form-submission-count-{$ownerRecord->getKey()}",
now()->addMinutes(5),
function () use ($ownerRecord): int {
return $ownerRecord->formSubmissions()->count();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,21 @@ protected function getStats(): array
return [
Stat::make('Students', Number::abbreviate(
Cache::tags(['{students}'])
->remember('{students-count}', now()->addHour(), function (): int {
->remember('students-count', now()->addHour(), function (): int {
return Student::count();
}),
maxPrecision: 2,
)),
Stat::make('Subscriptions', Cache::tags(['{students', "{user-{$user->getKey()}-student-subscriptions}"])
->remember("{user-{$user->getKey()}-student-subscriptions-count}", now()->addHour(), function () use ($user): int {
Stat::make('Subscriptions', Cache::tags(['{students', "user-{$user->getKey()}-student-subscriptions"])
->remember("user-{$user->getKey()}-student-subscriptions-count", now()->addHour(), function () use ($user): int {
return $user->studentSubscriptions()->count();
})),
Stat::make('Alerts', Cache::tags(['{students', "{user-{$user->getKey()}-student-alerts}"])
->remember("{user-{$user->getKey()}-student-alerts-count}", now()->addHour(), function () use ($user): int {
Stat::make('Alerts', Cache::tags(['{students}', "user-{$user->getKey()}-student-alerts"])
->remember("user-{$user->getKey()}-student-alerts-count", now()->addHour(), function () use ($user): int {
return $user->studentAlerts()->status(AlertStatus::Active)->count();
})),
Stat::make('Caseloads', Cache::tags(["{user-{$user->getKey()}-student-caseloads}"])
->remember("{user-{$user->getKey()}-student-caseloads-count}", now()->addHour(), function () use ($user): int {
->remember("user-{$user->getKey()}-student-caseloads-count", now()->addHour(), function () use ($user): int {
return $user->caseloads()->model(CaseloadModel::Student)->count();
})),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

// The cache key for the educatable should be busted
expect(Cache::has(
"{timeline.synced.{$initialResponse->sender->getMorphClass()}.{$initialResponse->sender->getKey()}}"
"timeline.synced.{$initialResponse->sender->getMorphClass()}.{$initialResponse->sender->getKey()}"
))->toBeFalse();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

// The cache key for the educatable should be busted
expect(Cache::has(
"{timeline.synced.{$initialResponse->sender->getMorphClass()}.{$initialResponse->sender->getKey()}}"
"timeline.synced.{$initialResponse->sender->getMorphClass()}.{$initialResponse->sender->getKey()}"
))->toBeFalse();
});

Expand Down
2 changes: 1 addition & 1 deletion app/Filament/Widgets/ProspectGrowthChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function getOptions(): array
protected function getData(): array
{
$runningTotalPerMonth = Cache::tags(['{prospects}'])
->remember('{prospect-growth-chart-data}', now()->addHour(), function (): array {
->remember('prospect-growth-chart-data', now()->addHour(), function (): array {
$totalCreatedPerMonth = Prospect::query()
->toBase()
->selectRaw('date_trunc(\'month\', created_at) as month')
Expand Down
1 change: 1 addition & 0 deletions docker/s6-overlay/s6-rc.d/clear-cache/dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
runas-user
1 change: 1 addition & 0 deletions docker/s6-overlay/s6-rc.d/clear-cache/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
1 change: 1 addition & 0 deletions docker/s6-overlay/s6-rc.d/clear-cache/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/scripts/clear-cache
19 changes: 19 additions & 0 deletions docker/s6-overlay/scripts/clear-cache
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/command/with-contenv bash

# Exit on error
set -e

# Check to see if an Artisan file exists and assume it means Laravel is configured.
if [ -f $WEBUSER_HOME/artisan ] && [ ${CLEAR_CACHE:="false"} == "true" ]; then
echo "Clearing the cache..."

USERNAME=$(id -nu $PUID)

s6-setuidgid $USERNAME php $WEBUSER_HOME/artisan cache:clear

echo "Cache Cleared!"
else
echo "Skipping clearing the cache because we could not detect a Laravel install or it was specifically not enabled..."
fi

exit 0
Empty file.