I have this data I'm trying to pull, but I have a lot of rows in the DB (over 100k) so it can take 12 secs to return results. Any ideas on how to improve performance?
$completedActivities = Activity::where('executed_at', '>', Carbon::now()->subDays(14))
->where('pending', false)
->where('user_id', auth()->user()->id)
->orderby('executed_at', 'desc')
->limit(100)->get();
Table structure:
Schema::create('activities', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedInteger('user_id');
$table->string('type');
$table->boolean('pending')->default(true);
$table->dateTime('pending_until')->nullable();
$table->dateTime('executed_at')->nullable();
$table->longText('execute')->nullable();
$table->softDeletes();
$table->timestamps();
});
I tried pulling only items from last 14 days (to reduce pulling all activities from db) and tried limiting to 100. any other ideas? refactor maybe?
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2pJGajB
via IFTTT
Aucun commentaire:
Enregistrer un commentaire