Skip to content

Commit

Permalink
Optimizing sql and improved Log data (#1883)
Browse files Browse the repository at this point in the history
* optimizing sql
* remove 2 relations, make sure that permissions are preloaded to avoid n+1 problem
* add Explain to mysql queries
  • Loading branch information
ildyria authored Jun 23, 2023
1 parent 6da4fd0 commit 0525fa8
Show file tree
Hide file tree
Showing 23 changed files with 785 additions and 134 deletions.
5 changes: 2 additions & 3 deletions app/Actions/Album/SetProtectionPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SetProtectionPolicy extends Action
public function do(BaseAlbum $album, AlbumProtectionPolicy $protectionPolicy, bool $shallSetPassword, ?string $password): void
{
$album->is_nsfw = $protectionPolicy->is_nsfw;
$active_permissions = $album->public_permissions;
$active_permissions = $album->public_permissions();

if (!$protectionPolicy->is_public) {
$active_permissions?->delete();
Expand Down Expand Up @@ -58,9 +58,8 @@ public function do(BaseAlbum $album, AlbumProtectionPolicy $protectionPolicy, bo
$active_permissions->password = null;
}
}
$album->public_permissions()->save($active_permissions);
$active_permissions->base_album_id = $album->id;
$active_permissions->save();
// $album->save();

// Reset permissions for photos
$album->photos()->update(['photos.is_public' => false]);
Expand Down
4 changes: 2 additions & 2 deletions app/Actions/Album/Unlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public function __construct()
*/
public function do(BaseAlbum $album, string $password): void
{
if ($album->public_permissions !== null) {
$album_password = $album->public_permissions->password;
if ($album->public_permissions() !== null) {
$album_password = $album->public_permissions()->password;
if (
$album_password === null ||
$album_password === '' ||
Expand Down
4 changes: 2 additions & 2 deletions app/Actions/Albums/Top.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ public function get(): TopAlbumsResource
}

$tagAlbumQuery = $this->albumQueryPolicy
->applyVisibilityFilter(TagAlbum::query()->with(['owner']));
->applyVisibilityFilter(TagAlbum::query()->with(['access_permissions', 'owner']));
/** @var BaseCollection<TagAlbum> $tagAlbums */
$tagAlbums = (new SortingDecorator($tagAlbumQuery))
->orderBy($this->sorting->column, $this->sorting->order)
->get();

/** @var NsQueryBuilder $query */
$query = $this->albumQueryPolicy
->applyVisibilityFilter(Album::query()->with(['owner'])->whereIsRoot());
->applyVisibilityFilter(Album::query()->with(['access_permissions', 'owner'])->whereIsRoot());

$userID = Auth::id();
if ($userID !== null) {
Expand Down
Loading

0 comments on commit 0525fa8

Please sign in to comment.