vendredi 18 septembre 2020

Get data within the current hour in laravel and sum with existing cache variable

Hi can anyone help this code to split up 24 hrs

       // as per my project today means  2020-09-19 12:00:00 -2020-09-20 11:59:59
        $date            = date('YmdHis', strtotime(' -12 hours '));
        $date_from       = date('Ymd120000', strtotime($date));
        $date_to         = Carbon::parse($date_from)->addDays(1)->format('Ymd115959');
        $product_reports = product_report::select(DB::raw('
                category_id , user_id , currency ,
                sum(price) as price , sum(tax) as tax , sum(discount) as discount '))
            ->whereBetween('created_at', [$date_from, $date_to])
            ->groupBy(DB::raw('
                category_id , product_id , user_id
            '))
            ->get();

        Cache::forget('cached_report');
        Cache::forever('cached_report', $product_reports );

this code i maintain as cron job it run every 5min once and store in cached_report but here am facing issue as when this query start execute it takes more then 1 min. so this can be spilted by Hour based like

2020-09-19 12:00:00 to 2020-09-19 12:59:59
2020-09-19 13:00:00 to 2020-09-19 13:59:59
2020-09-19 14:00:00 to 2020-09-19 14:59:59
.
.
2020-09-20 00:00:00 to 2020-09-20 00:59:59
.
.
2020-09-20 11:00:00 to 2020-09-2011:59:59

Llike

then just run cron for 1 Hrs data only for each 5mins

Ex/; now time 8pm 2020-09-19 18:00:00-18:59:59 just call this time only

and add this with previous result



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3iJXICa
via IFTTT

Aucun commentaire:

Enregistrer un commentaire