Skip to content

560: flush in repository#443

Merged
ilaria-orlando merged 1 commit into
masterfrom
560-flush-in-repository
Jun 1, 2026
Merged

560: flush in repository#443
ilaria-orlando merged 1 commit into
masterfrom
560-flush-in-repository

Conversation

@ilaria-orlando
Copy link
Copy Markdown

@ilaria-orlando ilaria-orlando commented May 28, 2026

Type

  • Enhancement

Pull request description

Fish inside repository instead of inside the message handlers for ContentBlock, MediaGallery and MediaLibrary modules

Summary by Sourcery

Move transaction flushing responsibility from message handlers into the domain repositories for content blocks, media galleries, and media folders.

Enhancements:

  • Introduce repository-level save() methods that flush the entity manager for content blocks, media galleries, and media folders.
  • Update command handlers to depend on repositories instead of the generic entity manager and to stop calling flush() directly.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 28, 2026

Reviewer's Guide

Moves Doctrine flush responsibility from message handlers to the domain repositories for ContentBlocks, MediaGalleries, and MediaLibrary folders, introducing repository-level save() methods and updating handlers to depend on repositories instead of the raw EntityManager for persistence lifecycle control.

Sequence diagram for repository-managed flushing in command handlers

sequenceDiagram
    participant Handler as CreateContentBlockHandler
    participant Repository as ContentBlockRepository
    participant EntityManager as EntityManagerInterface

    Handler->>Repository: add(ContentBlock)
    Repository->>EntityManager: persist(ContentBlock)
    Repository->>Repository: save()
    Repository->>EntityManager: flush()
Loading

File-Level Changes

Change Details Files
Introduce repository-level save() methods that flush the Doctrine EntityManager and invoke them from add/remove operations instead of relying on external handlers to flush.
  • Add save() method to ContentBlockRepository, MediaFolderRepository, and MediaGalleryRepository that calls EntityManager::flush()
  • Update repository add/remove methods to call save() after persist/remove
  • Remove old inline comments explaining why flush was not called in repositories
src/Backend/Modules/ContentBlocks/Domain/ContentBlock/ContentBlockRepository.php
src/Backend/Modules/MediaLibrary/Domain/MediaFolder/MediaFolderRepository.php
src/Backend/Modules/MediaGalleries/Domain/MediaGallery/MediaGalleryRepository.php
Refactor command/message handlers to delegate flushing to their repositories and reduce direct EntityManager usage.
  • Remove EntityManagerInterface constructor dependencies from ContentBlock, MediaGallery, and MediaFolder command handlers where no longer needed
  • Replace direct EntityManager::flush() calls with repository->save() in UpdateMediaGalleryHandler and UpdateMediaFolderHandler
  • Remove now-unnecessary flush calls from create/copy/update/delete handlers for ContentBlocks, MediaGalleries, and MediaFolders
  • Inject MediaGalleryRepository and MediaFolderRepository in update handlers instead of the raw EntityManager
src/Backend/Modules/MediaGalleries/Domain/MediaGallery/Command/UpdateMediaGalleryHandler.php
src/Backend/Modules/MediaLibrary/Domain/MediaFolder/Command/UpdateMediaFolderHandler.php
src/Backend/Modules/ContentBlocks/Domain/ContentBlock/Command/CopyContentBlocksToOtherLocaleHandler.php
src/Backend/Modules/ContentBlocks/Domain/ContentBlock/Command/CreateContentBlockHandler.php
src/Backend/Modules/ContentBlocks/Domain/ContentBlock/Command/DeleteContentBlockHandler.php
src/Backend/Modules/ContentBlocks/Domain/ContentBlock/Command/UpdateContentBlockHandler.php
src/Backend/Modules/MediaGalleries/Domain/MediaGallery/Command/CreateMediaGalleryHandler.php
src/Backend/Modules/MediaGalleries/Domain/MediaGallery/Command/DeleteMediaGalleryHandler.php
src/Backend/Modules/MediaLibrary/Domain/MediaFolder/Command/CreateMediaFolderHandler.php
src/Backend/Modules/MediaLibrary/Domain/MediaFolder/Command/DeleteMediaFolderHandler.php

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • In CopyContentBlocksToOtherLocaleHandler you now call ContentBlockRepository::add() in a loop where add() immediately flushes, which changes the previous behavior of a single batched flush at the end—consider adding a way to perform a single flush after all additions (e.g. separate persist() vs save() or a bulk saveAll()) to avoid performance regressions.
  • With repositories now responsible for flushing, review other call sites where multiple add/remove calls can occur in a single operation to ensure you're not unintentionally flushing after each call; it might be useful to separate persistence from flushing for batch scenarios.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `CopyContentBlocksToOtherLocaleHandler` you now call `ContentBlockRepository::add()` in a loop where `add()` immediately flushes, which changes the previous behavior of a single batched flush at the end—consider adding a way to perform a single flush after all additions (e.g. separate `persist()` vs `save()` or a bulk `saveAll()`) to avoid performance regressions.
- With repositories now responsible for flushing, review other call sites where multiple `add`/`remove` calls can occur in a single operation to ensure you're not unintentionally flushing after each call; it might be useful to separate persistence from flushing for batch scenarios.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@ilaria-orlando ilaria-orlando merged commit a04bfd7 into master Jun 1, 2026
10 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants