1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-28 17:02:04 +03:00

Optimized loading of page/chapter URLs to be a little more efficient

- Loaded book_slug as part of chapter/page queries instead of books
 being loaded in afterwards.
- Removed unused page method.
- Updated some page queries to load specific attributes.
This commit is contained in:
Dan Brown
2021-08-21 19:58:19 +01:00
parent 8db047de70
commit 1a6293ce24
5 changed files with 26 additions and 21 deletions

View File

@ -10,14 +10,29 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
*
* @property int $book_id
* @property int $priority
* @property string $book_slug
* @property Book $book
*
* @method Builder whereSlugs(string $bookSlug, string $childSlug)
*/
abstract class BookChild extends Entity
{
protected static function boot()
{
parent::boot();
// Load book slugs onto these models by default during query-time
static::addGlobalScope('book_slug', function(Builder $builder) {
$builder->addSelect(['book_slug' => function($builder) {
$builder->select('slug')
->from('books')
->whereColumn('books.id', '=', 'book_id');
}]);
});
}
/**
* Scope a query to find items where the the child has the given childSlug
* Scope a query to find items where the child has the given childSlug
* where its parent has the bookSlug.
*/
public function scopeWhereSlugs(Builder $query, string $bookSlug, string $childSlug)