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:
@ -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>'
|
||||
];
|
||||
});
|
||||
|
89
database/migrations/2015_11_26_221857_add_entity_indexes.php
Normal file
89
database/migrations/2015_11_26_221857_add_entity_indexes.php
Normal 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');
|
||||
});
|
||||
}
|
||||
}
|
29
database/seeds/DummyContentSeeder.php
Normal file
29
database/seeds/DummyContentSeeder.php
Normal 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);
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user