diff options
| author | horus | 2022-09-25 02:34:42 +0200 |
|---|---|---|
| committer | horus | 2022-09-25 02:34:42 +0200 |
| commit | acbe243bcd4c2dade2a834ce6bdedf46d1d10ae2 (patch) | |
| tree | 0f12c3a667b3b4c4f451d874601bc63b726679c1 | |
| parent | 1c5a5b7cb014843f533d1473c5b3c6d6350acb40 (diff) | |
| download | kategorischeraperitif-acbe243bcd4c2dade2a834ce6bdedf46d1d10ae2.tar.gz | |
Sitemap, Cache etc
| -rw-r--r-- | app/Console/Commands/GenerateSitemap.php | 10 | ||||
| -rw-r--r-- | app/Console/Kernel.php | 5 | ||||
| -rw-r--r-- | app/Http/Controllers/IndexController.php | 18 | ||||
| -rw-r--r-- | app/Libraries/Helper.php | 55 |
4 files changed, 79 insertions, 9 deletions
diff --git a/app/Console/Commands/GenerateSitemap.php b/app/Console/Commands/GenerateSitemap.php index 089f60a..87837b5 100644 --- a/app/Console/Commands/GenerateSitemap.php +++ b/app/Console/Commands/GenerateSitemap.php @@ -4,6 +4,7 @@ namespace App\Console\Commands; use Illuminate\Console\Command; use Spatie\Sitemap\SitemapGenerator; +use Spatie\Crawler\Crawler; class GenerateSitemap extends Command { @@ -38,8 +39,11 @@ class GenerateSitemap extends Command */ public function handle() { - // modify this to your own needs - SitemapGenerator::create(config('app.url')) - ->writeToFile(public_path('sitemap.xml')); + // modify this to your own needs + SitemapGenerator::create(config('app.url')) + ->configureCrawler(function (Crawler $crawler) { + $crawler->ignoreRobots(); + }) + ->writeToFile(public_path('sitemap.xml')); } } diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 300e1a3..4321192 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -5,6 +5,8 @@ namespace App\Console; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; +use App\Libraries\Helper; + class Kernel extends ConsoleKernel { /** @@ -25,6 +27,9 @@ class Kernel extends ConsoleKernel protected function schedule(Schedule $schedule) { $schedule->command('sitemap:generate')->daily(); + #$schedule->command('sitemap:generate')->everyMinute(); + + $schedule->call( function(){ Helper::fillCache(); } )->hourly(); } /** diff --git a/app/Http/Controllers/IndexController.php b/app/Http/Controllers/IndexController.php index c53fc2a..2c34a55 100644 --- a/app/Http/Controllers/IndexController.php +++ b/app/Http/Controllers/IndexController.php @@ -27,21 +27,22 @@ class IndexController extends Controller { $data = Cache::get('angebote_index'); } else { - $data = $this->getAngeboteData($request); + #$data = $this->getAngeboteData($request); + $data = Helper::getAngeboteData(); Cache::put('angebote_index', $data , 6000); // 100 minutes } if ( Cache::has('angebote_count') ) { $count = Cache::get('angebote_count'); } else { - $count = DB::select("SELECT count(*) as count FROM all_view")[0]; + #$count = DB::select("SELECT count(*) as count FROM all_view")[0]; + $count = Helper::getAngeboteCount(); Cache::put('angebote_count', $count, 6000); // 100 minutes } #$count = DB::select("SELECT count(*) as count FROM all_view")[0]; - $cache_angebote = view('fragments.angebote', ['data' => $data, 'views' => $views, 'hits' => $count])->render(); - return view('angebote_index', ['data' => $data, 'views' => $views, 'hits' => $count, 'cache_angebote' => $cache_angebote])->render(); + return view('angebote_index', ['data' => $data, 'views' => $views, 'hits' => $count])->render(); } public function index(Request $request) { @@ -51,21 +52,26 @@ class IndexController extends Controller { $data = Cache::get('angebote_index'); } else { - $data = $this->getAngeboteData($request); + #$data = $this->getAngeboteData($request); + $data = Helper::getAngeboteData(); Cache::put('angebote_index', $data , 6000); // 100 minutes } if ( Cache::has('angebote_count') ) { $count= Cache::get('angebote_count'); } else { - $count = DB::select("SELECT count(*) as count FROM all_view")[0]; + #$count = DB::select("SELECT count(*) as count FROM all_view")[0]; + $count = Helper::getAngeboteCount(); Cache::put('angebote_count', $count, 6000); // 100 minutes } if ( Cache::has('cocktail_count') ) { $cocktail_count= Cache::get('cocktail_count'); } else { + /* $cocktails = new Cocktail; $cocktail_count = $cocktails->count(); + */ + $cocktail_count = Helper::getCocktailCount(); Cache::put('cocktail_count', $cocktail_count, 6000); // 100 minutes } diff --git a/app/Libraries/Helper.php b/app/Libraries/Helper.php index 1e9741e..a5556fd 100644 --- a/app/Libraries/Helper.php +++ b/app/Libraries/Helper.php @@ -1,7 +1,11 @@ <?php namespace App\Libraries; use App\Libraries\Helper; +use App\Cocktail; +use App\Ingredient; use Carbon\Carbon; +use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Cache; class Helper { public static function escapeLike($string){ @@ -24,4 +28,55 @@ class Helper { } return false; } + + + public static function getAngeboteData() { + $views = array("whisky", "wodka", "gin", "rum", "misc"); + $query = ""; + + foreach($views as $view) { + if ($query != "") { + $query .= " UNION "; + } + $query .= " + (SELECT + name, + image_url, + spirit_type, + spirit_type AS url, + spirit_type AS angebotsname, + (SELECT MAX(procent) FROM " . $view . "_view) as procent, + '' AS linktext FROM ". $view ."_view + WHERE + original_price > 29.98 + AND + spirit_type != 'Verschiedenes' + AND + shop != 'Rum & Co' + AND + shop = 'Drankdozijn' + ORDER BY + created_at DESC, + procent DESC LIMIT 1)"; + } + + $data = DB::select($query); + + return $data; + } + + public static function getAngeboteCount() { + return DB::select("SELECT count(*) as count FROM all_view")[0]; + } + + public static function getCocktailCount() { + $cocktails = new Cocktail; + return $cocktails->count(); + } + + public static function fillCache(){ + Cache::put('angebote_count', Helper::getAngeboteCount(), 6000); // 100 minutes + Cache::put('cocktail_count', Helper::getCocktailCount(), 6000); // 100 minutes + Cache::put('angebote_index', Helper::getAngeboteData(), 6000); // 100 minutes + } } |
