Updated label and DNS count to use cache

Updated label and DNS count to use cache
This commit is contained in:
cp6 2022-05-15 00:15:20 +10:00
parent 3ff6cfe56e
commit 779412a8da
4 changed files with 26 additions and 1 deletions

View File

@ -10,6 +10,7 @@ use App\Models\Domains;
use App\Models\Shared; use App\Models\Shared;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str; use Illuminate\Support\Str;
@ -59,6 +60,8 @@ class DNSController extends Controller
} }
} }
Cache::forget('dns_count');
return redirect()->route('dns.index') return redirect()->route('dns.index')
->with('success', 'DNS Created Successfully.'); ->with('success', 'DNS Created Successfully.');
} }
@ -87,7 +90,7 @@ class DNSController extends Controller
->where('l.service_id', '=', $dn->id) ->where('l.service_id', '=', $dn->id)
->get(['labels.id', 'labels.label']); ->get(['labels.id', 'labels.label']);
return view('dns.edit', compact(['dn', 'labels','Servers', 'Domains', 'Shareds', 'Resellers'])); return view('dns.edit', compact(['dn', 'labels', 'Servers', 'Domains', 'Shareds', 'Resellers']));
} }
public function update(Request $request, DNS $dn) public function update(Request $request, DNS $dn)
@ -130,6 +133,8 @@ class DNSController extends Controller
$items->delete(); $items->delete();
Cache::forget('dns_count');
Labels::deleteLabelsAssignedTo($id); Labels::deleteLabelsAssignedTo($id);
return redirect()->route('dns.index') return redirect()->route('dns.index')

View File

@ -34,6 +34,7 @@ class LabelsController extends Controller
]); ]);
Cache::forget('all_labels'); Cache::forget('all_labels');
Cache::forget('labels_count');
return redirect()->route('labels.index') return redirect()->route('labels.index')
->with('success', 'Label Created Successfully.'); ->with('success', 'Label Created Successfully.');
@ -66,6 +67,8 @@ class LabelsController extends Controller
$items->delete(); $items->delete();
Cache::forget('labels_count');
Labels::deleteLabelAssignedAs($label_id); Labels::deleteLabelAssignedAs($label_id);
Cache::forget('all_labels'); Cache::forget('all_labels');

View File

@ -4,6 +4,8 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
class DNS extends Model class DNS extends Model
{ {
@ -14,4 +16,11 @@ class DNS extends Model
protected $fillable = ['id', 'service_id', 'hostname', 'dns_type', 'address', 'server_id', 'domain_id']; protected $fillable = ['id', 'service_id', 'hostname', 'dns_type', 'address', 'server_id', 'domain_id'];
public static $dns_types = ['A', 'AAAA', 'DNAME', 'MX', 'NS', 'SOA', 'TXT', 'URI']; public static $dns_types = ['A', 'AAAA', 'DNAME', 'MX', 'NS', 'SOA', 'TXT', 'URI'];
public static function dnsCount()
{
return Cache::remember('dns_count', now()->addMonth(1), function () {
return DB::table('d_n_s')->count();
});
}
} }

View File

@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
class Labels extends Model class Labels extends Model
@ -33,4 +34,11 @@ class Labels extends Model
} }
} }
public static function labelsCount()
{
return Cache::remember('labels_count', now()->addMonth(1), function () {
return DB::table('labels')->count();
});
}
} }