1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-31 15:24:31 +03:00

Added indexes, Reduced queries on pages

This commit is contained in:
Dan Brown
2015-11-26 23:45:04 +00:00
parent 3825ea8c14
commit 22f8a408fa
19 changed files with 319 additions and 48 deletions

View File

@ -23,6 +23,7 @@ $factory->define(BookStack\User::class, function ($faker) {
$factory->define(BookStack\Book::class, function ($faker) {
return [
'name' => $faker->sentence,
'slug' => str_random(10),
'description' => $faker->paragraph
];
});
@ -30,6 +31,7 @@ $factory->define(BookStack\Book::class, function ($faker) {
$factory->define(BookStack\Chapter::class, function ($faker) {
return [
'name' => $faker->sentence,
'slug' => str_random(10),
'description' => $faker->paragraph
];
});
@ -37,6 +39,7 @@ $factory->define(BookStack\Chapter::class, function ($faker) {
$factory->define(BookStack\Page::class, function ($faker) {
return [
'name' => $faker->sentence,
'slug' => str_random(10),
'html' => '<p>' . implode('</p>', $faker->paragraphs(5)) . '</p>'
];
});

View File

@ -0,0 +1,89 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddEntityIndexes extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('books', function (Blueprint $table) {
$table->index('slug');
$table->index('created_by');
$table->index('updated_by');
});
Schema::table('pages', function (Blueprint $table) {
$table->index('slug');
$table->index('book_id');
$table->index('chapter_id');
$table->index('priority');
$table->index('created_by');
$table->index('updated_by');
});
Schema::table('page_revisions', function (Blueprint $table) {
$table->index('page_id');
});
Schema::table('chapters', function (Blueprint $table) {
$table->index('slug');
$table->index('book_id');
$table->index('priority');
$table->index('created_by');
$table->index('updated_by');
});
Schema::table('activities', function (Blueprint $table) {
$table->index('book_id');
$table->index('user_id');
$table->index('entity_id');
});
Schema::table('views', function (Blueprint $table) {
$table->index('user_id');
$table->index('viewable_id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('books', function (Blueprint $table) {
$table->dropIndex('slug');
$table->dropIndex('created_by');
$table->dropIndex('updated_by');
});
Schema::table('pages', function (Blueprint $table) {
$table->dropIndex('slug');
$table->dropIndex('book_id');
$table->dropIndex('chapter_id');
$table->dropIndex('priority');
$table->dropIndex('created_by');
$table->dropIndex('updated_by');
});
Schema::table('page_revisions', function (Blueprint $table) {
$table->dropIndex('page_id');
});
Schema::table('chapters', function (Blueprint $table) {
$table->dropIndex('slug');
$table->dropIndex('book_id');
$table->dropIndex('priority');
$table->dropIndex('created_by');
$table->dropIndex('updated_by');
});
Schema::table('activities', function (Blueprint $table) {
$table->dropIndex('book_id');
$table->dropIndex('user_id');
$table->dropIndex('entity_id');
});
Schema::table('views', function (Blueprint $table) {
$table->dropIndex('user_id');
$table->dropIndex('entity_id');
});
}
}

View File

@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Seeder;
class DummyContentSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$user = factory(BookStack\User::class, 1)->create();
$role = \BookStack\Role::where('name', '=', 'admin')->first();
$user->attachRole($role);
$books = factory(BookStack\Book::class, 20)->create(['created_by' => $user->id, 'updated_by' => $user->id])
->each(function($book) use ($user) {
$chapters = factory(BookStack\Chapter::class, 5)->create(['created_by' => $user->id, 'updated_by' => $user->id])
->each(function($chapter) use ($user, $book){
$pages = factory(\BookStack\Page::class, 10)->make(['created_by' => $user->id, 'updated_by' => $user->id, 'book_id' => $book->id]);
$chapter->pages()->saveMany($pages);
});
$book->chapters()->saveMany($chapters);
});
}
}