lundi 25 novembre 2019

Fetch the details from database using laravel

I am trying to get the details from database and written below Laravel code to fetch the details from two table using join query. But it is taking too much time while fetching the data.

Can you guys help me? So it will take minimum time to fetch the API.

   public function getWebsiteVisitorsDetails($businessId, $startTime, $endTime, $filterType){
        $chatBotClicked = DB::table('chatbot_website_visitor_detail')
            ->join('website_visitors_task', 'website_visitors_task.website_session_id', '=', 'chatbot_website_visitor_detail.website_session_id')
            ->where('website_visitors_task.session_task_perform' , 3)
            ->where('chatbot_website_visitor_detail.business_id', $businessId);
        if($filterType != ApiConstant::ALL_TIME){
            $chatBotClicked = $chatBotClicked->whereBetween('website_visitors_task.created_at', [$startTime, $endTime]);
        }

        $feedbackClicked = DB::table('chatbot_website_visitor_detail')
            ->join('website_visitors_task', 'website_visitors_task.website_session_id', '=', 'chatbot_website_visitor_detail.website_session_id')
            ->where('website_visitors_task.session_task_perform' , 2)
            ->where('chatbot_website_visitor_detail.business_id', $businessId);
        if($filterType != ApiConstant::ALL_TIME){
            $feedbackClicked = $feedbackClicked->whereBetween('website_visitors_task.created_at', [$startTime, $endTime]);
        }

        $firstTimeVisitor = DB::table('chatbot_website_visitor_detail')
            ->select('chatbot_website_visitor_detail.id')
            ->where('chatbot_website_visitor_detail.business_id', $businessId)
            ->where('chatbot_website_visitor_detail.from_popup_widget', 1);
        if($filterType != ApiConstant::ALL_TIME){
            $firstTimeVisitor = $firstTimeVisitor->whereBetween('chatbot_website_visitor_detail.created_at', [$startTime, $endTime]);
        }

        $returnData['chatbot_clicked'] = $chatBotClicked->count();
        $returnData['feedback_clicked'] = $feedbackClicked->count();
        $returnData['first_time_user'] = $firstTimeVisitor->count();
    }


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire