[PR #4827] [MERGED] Update of entity loading to be more efficient and avoid global addSelects #6413

Closed
opened 2026-02-05 10:31:38 +03:00 by OVERLORD · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/BookStackApp/BookStack/pull/4827
Author: @ssddanbrown
Created: 2/4/2024
Status: Merged
Merged: 2/11/2024
Merged by: @ssddanbrown

Base: developmentHead: query_revamp


📝 Commits (10+)

  • a70ed81 DB: Started update of entity loading to avoid global selects
  • 1559b0a Queries: Migrated BookRepo queries to new query class
  • 3886aed Queries: Migrated bookshelf repo queries to new class
  • 8e78b4c Queries: Extracted chapter repo queries to class
  • 222c665 Queries: Extracted PageRepo queries to own class
  • c95f4ca Queries: Migrated revision repo queries to new class
  • 4834107 Queries: Updated all app book static query uses
  • 546cfb0 Queries: Extracted static page,chapter,shelf queries to classes
  • b77ab6f Queries: Moved out or removed some class-level items
  • ed21a6d Queries: Updated old use-specific entity query classes

📊 Changes

87 files changed (+1201 additions, -918 deletions)

View changed files

📝 app/Activity/ActivityQueries.php (+8 -6)
📝 app/Activity/Controllers/CommentController.php (+4 -3)
📝 app/Activity/Controllers/FavouriteController.php (+3 -3)
📝 app/Api/ApiDocsGenerator.php (+0 -1)
📝 app/App/HomeController.php (+26 -18)
📝 app/App/Providers/ThemeServiceProvider.php (+0 -1)
📝 app/Config/clockwork.php (+2 -0)
📝 app/Console/Commands/CopyShelfPermissionsCommand.php (+4 -4)
📝 app/Entities/Controllers/BookApiController.php (+9 -5)
📝 app/Entities/Controllers/BookController.php (+21 -16)
📝 app/Entities/Controllers/BookExportApiController.php (+9 -10)
📝 app/Entities/Controllers/BookExportController.php (+9 -15)
📝 app/Entities/Controllers/BookSortController.php (+7 -9)
📝 app/Entities/Controllers/BookshelfApiController.php (+9 -5)
📝 app/Entities/Controllers/BookshelfController.php (+24 -13)
📝 app/Entities/Controllers/ChapterApiController.php (+19 -13)
📝 app/Entities/Controllers/ChapterController.php (+25 -17)
📝 app/Entities/Controllers/ChapterExportApiController.php (+9 -13)
📝 app/Entities/Controllers/ChapterExportController.php (+9 -15)
📝 app/Entities/Controllers/PageApiController.php (+14 -12)

...and 67 more files

📄 Description

  • Removes page/chpater addSelect global query, to load book slug.
  • Updates querying of all items to be limited to a few non-static classes, one per entity type.
    • This reduces the mixed-purpose of repos to focus on CRUD actions, moving out the query stuff to be usable elsewhere.
  • Makes use of our more efficient MixedEntityListLoader where appropriate.
  • Adds some database indexes where it can make a measurable performance impact.

Related to #4823

Todo

  • Migrate all book repo query usages.
  • Migrate all shelf repo query usages.
  • Migrate all chapter repo query usages.
  • Migrate all page repo query usages.
  • Migrate all page revision query usages.
  • Remove redundant Bookchild code.
  • Migrate all static book queries.
  • Migrate all static shelf queries.
  • Migrate all static chapter queries.
  • Migrate all static page queries.
  • Maybe clean up old Entities/Queries folder? Or at least do something with the old EntitiyQuery class to not be named so close to newly added classes.
  • Review existing page/chapter lists for performance and query efficiency.
  • Update API queries
  • Check API differences before/after usage, and compare with API docs, to decide on supporting old columns or indicate change for update notes.
    • Note: Changes were made to remain compatible with pre-PR state, which already aligned with docs.
    • Books
    • Shelves
    • Pages
    • Chpaters
  • Update existing page/chapter queries.
  • See if the $listAttributes is now better placed in the PageQueries class.
    • Also check how those in MixedEntityListLoader align, and share if reasonable.
  • Double check through all queries to ensure visible scope enforced where intended.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/BookStackApp/BookStack/pull/4827 **Author:** [@ssddanbrown](https://github.com/ssddanbrown) **Created:** 2/4/2024 **Status:** ✅ Merged **Merged:** 2/11/2024 **Merged by:** [@ssddanbrown](https://github.com/ssddanbrown) **Base:** `development` ← **Head:** `query_revamp` --- ### 📝 Commits (10+) - [`a70ed81`](https://github.com/BookStackApp/BookStack/commit/a70ed81908a8bcd67e6c449eb7d0cdd6f26ef998) DB: Started update of entity loading to avoid global selects - [`1559b0a`](https://github.com/BookStackApp/BookStack/commit/1559b0acd1018edff3f173df0c87f631549462fa) Queries: Migrated BookRepo queries to new query class - [`3886aed`](https://github.com/BookStackApp/BookStack/commit/3886aedf54873a1bf90cfdaa9cafc6f22c1d03fd) Queries: Migrated bookshelf repo queries to new class - [`8e78b4c`](https://github.com/BookStackApp/BookStack/commit/8e78b4c43eb980f47d9c207a0ce3330699d54103) Queries: Extracted chapter repo queries to class - [`222c665`](https://github.com/BookStackApp/BookStack/commit/222c665018cd7fc231d2970307e3a7423e4a377f) Queries: Extracted PageRepo queries to own class - [`c95f4ca`](https://github.com/BookStackApp/BookStack/commit/c95f4ca40fecf0584eccb5f89d49b245d4ec7369) Queries: Migrated revision repo queries to new class - [`4834107`](https://github.com/BookStackApp/BookStack/commit/483410749bdfb03d1e3fb98db82c092583a88449) Queries: Updated all app book static query uses - [`546cfb0`](https://github.com/BookStackApp/BookStack/commit/546cfb0dcc801c4fa6560ca0e6d18b4f1edd830f) Queries: Extracted static page,chapter,shelf queries to classes - [`b77ab6f`](https://github.com/BookStackApp/BookStack/commit/b77ab6f3af996f924bd2ddbac6e88f61a8bf6cf9) Queries: Moved out or removed some class-level items - [`ed21a6d`](https://github.com/BookStackApp/BookStack/commit/ed21a6d798a5a7b4148bf388051c016a2b3315e4) Queries: Updated old use-specific entity query classes ### 📊 Changes **87 files changed** (+1201 additions, -918 deletions) <details> <summary>View changed files</summary> 📝 `app/Activity/ActivityQueries.php` (+8 -6) 📝 `app/Activity/Controllers/CommentController.php` (+4 -3) 📝 `app/Activity/Controllers/FavouriteController.php` (+3 -3) 📝 `app/Api/ApiDocsGenerator.php` (+0 -1) 📝 `app/App/HomeController.php` (+26 -18) 📝 `app/App/Providers/ThemeServiceProvider.php` (+0 -1) 📝 `app/Config/clockwork.php` (+2 -0) 📝 `app/Console/Commands/CopyShelfPermissionsCommand.php` (+4 -4) 📝 `app/Entities/Controllers/BookApiController.php` (+9 -5) 📝 `app/Entities/Controllers/BookController.php` (+21 -16) 📝 `app/Entities/Controllers/BookExportApiController.php` (+9 -10) 📝 `app/Entities/Controllers/BookExportController.php` (+9 -15) 📝 `app/Entities/Controllers/BookSortController.php` (+7 -9) 📝 `app/Entities/Controllers/BookshelfApiController.php` (+9 -5) 📝 `app/Entities/Controllers/BookshelfController.php` (+24 -13) 📝 `app/Entities/Controllers/ChapterApiController.php` (+19 -13) 📝 `app/Entities/Controllers/ChapterController.php` (+25 -17) 📝 `app/Entities/Controllers/ChapterExportApiController.php` (+9 -13) 📝 `app/Entities/Controllers/ChapterExportController.php` (+9 -15) 📝 `app/Entities/Controllers/PageApiController.php` (+14 -12) _...and 67 more files_ </details> ### 📄 Description - Removes page/chpater addSelect global query, to load book slug. - Updates querying of all items to be limited to a few non-static classes, one per entity type. - This reduces the mixed-purpose of repos to focus on CRUD actions, moving out the query stuff to be usable elsewhere. - Makes use of our more efficient MixedEntityListLoader where appropriate. - Adds some database indexes where it can make a measurable performance impact. Related to #4823 ### Todo - [x] Migrate all book repo query usages. - [x] Migrate all shelf repo query usages. - [x] Migrate all chapter repo query usages. - [x] Migrate all page repo query usages. - [x] Migrate all page revision query usages. - [x] Remove redundant Bookchild code. - [x] Migrate all static book queries. - [x] Migrate all static shelf queries. - [x] Migrate all static chapter queries. - [x] Migrate all static page queries. - [x] Maybe clean up old `Entities/Queries` folder? Or at least do something with the old `EntitiyQuery` class to not be named so close to newly added classes. - [x] Review existing page/chapter lists for performance and query efficiency. - [x] Update API queries - [x] Check API differences before/after usage, and compare with API docs, to decide on supporting old columns or indicate change for update notes. - Note: Changes were made to remain compatible with pre-PR state, which already aligned with docs. - [x] Books - [x] Shelves - [x] Pages - [x] Chpaters - [x] Update existing page/chapter queries. - [x] See if the `$listAttributes` is now better placed in the PageQueries class. - [x] Also check how those in `MixedEntityListLoader` align, and share if reasonable. - [x] Double check through all queries to ensure visible scope enforced where intended. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
OVERLORD added the pull-request label 2026-02-05 10:31:38 +03:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#6413