Skip to content

Commit

Permalink
Disable form submissions count cache + increase ttl
Browse files Browse the repository at this point in the history
  • Loading branch information
JhumanJ committed Dec 2, 2023
1 parent a6e208a commit 508358d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
11 changes: 4 additions & 7 deletions app/Models/Forms/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
class Form extends Model implements CachableAttributes
{
use CachesAttributes;

const DARK_MODE_VALUES = ['auto', 'light', 'dark'];
const THEMES = ['default', 'simple', 'notion'];
const WIDTHS = ['centered', 'full'];
Expand Down Expand Up @@ -131,7 +132,6 @@ class Form extends Model implements CachableAttributes

protected $cachableAttributes = [
'is_pro',
'submissions_count',
'views_count',
];

Expand All @@ -146,7 +146,7 @@ class Form extends Model implements CachableAttributes

public function getIsProAttribute()
{
return $this->remember('is_pro', 15, function(): bool {
return $this->remember('is_pro', 15 * 60, function (): bool {
return optional($this->workspace)->is_pro;
});
}
Expand All @@ -166,14 +166,12 @@ public function getEditUrlAttribute()

public function getSubmissionsCountAttribute()
{
return $this->remember('submissions_count', 5, function(): int {
return $this->submissions()->count();
});
return $this->submissions()->count();
}

public function getViewsCountAttribute()
{
return $this->remember('views_count', 5, function(): int {
return $this->remember('views_count', 15 * 60, function (): int {
if (env('DB_CONNECTION') == 'mysql') {
return (int)($this->views()->count() +
$this->statistics()->sum(DB::raw("json_extract(data, '$.views')")));
Expand Down Expand Up @@ -218,7 +216,6 @@ public function getFormPendingSubmissionKeyAttribute()

public function getMaxNumberOfSubmissionsReachedAttribute()
{
$this->forget('submissions_count');
return ($this->max_submissions_count && $this->max_submissions_count <= $this->submissions_count);
}

Expand Down
12 changes: 6 additions & 6 deletions app/Models/Workspace.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function getMaxFileSizeAttribute()
return self::MAX_FILE_SIZE_PRO;
}

return $this->remember('max_file_size', 15, function(): int {
return $this->remember('max_file_size', 15 * 60, function(): int {
// Return max file size depending on subscription
foreach ($this->owners as $owner) {
if ($owner->is_subscribed) {
Expand All @@ -71,7 +71,7 @@ public function getCustomDomainCountLimitAttribute()
return null;
}

return $this->remember('custom_domain_count', 15, function(): int {
return $this->remember('custom_domain_count', 15 * 60, function(): int {
foreach ($this->owners as $owner) {
if ($owner->is_subscribed) {
if ($license = $owner->activeLicense()) {
Expand All @@ -92,7 +92,7 @@ public function getIsProAttribute()
return true; // If no paid plan so TRUE for ALL
}

return $this->remember('is_pro', 15, function(): bool {
return $this->remember('is_pro', 15 * 60, function(): bool {
// Make sure at least one owner is pro
foreach ($this->owners as $owner) {
if ($owner->is_subscribed) {
Expand All @@ -109,7 +109,7 @@ public function getIsEnterpriseAttribute()
return true; // If no paid plan so TRUE for ALL
}

return $this->remember('is_enterprise', 15, function(): bool {
return $this->remember('is_enterprise', 15 * 60, function(): bool {
// Make sure at least one owner is pro
foreach ($this->owners as $owner) {
if ($owner->has_enterprise_subscription) {
Expand All @@ -122,7 +122,7 @@ public function getIsEnterpriseAttribute()

public function getIsRiskyAttribute()
{
return $this->remember('is_risky', 15, function(): bool {
return $this->remember('is_risky', 15 * 60, function(): bool {
// A workspace is risky if all of his users are risky
foreach ($this->owners as $owner) {
if (!$owner->is_risky) {
Expand All @@ -136,7 +136,7 @@ public function getIsRiskyAttribute()

public function getSubmissionsCountAttribute()
{
return $this->remember('submissions_count', 15, function(): int {
return $this->remember('submissions_count', 15 * 60, function(): int {
$total = 0;
foreach ($this->forms as $form) {
$total += $form->submissions_count;
Expand Down

0 comments on commit 508358d

Please sign in to comment.