Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes 2: Plain Text Handler Refactoring #6439

Merged
merged 5 commits into from
May 25, 2024

Conversation

bastianallgeier
Copy link
Member

@bastianallgeier bastianallgeier commented May 6, 2024

This PR …

Refactoring

  • New internal PlainTextContentStorageHandler::write method
  • New contentFile methods to split logic per model type and make use of type hinting
  • Remove option to pass null as language to ContentStorageHandler::exists to avoid unwanted logic in handler methods.
  • Alphabetically sorted methods

Outlook

  • All $lang arguments in handler methods will be converted to full Language objects instead of strings in a later PR. I did not solve all of this at once to keep the PR more straight forward. Changes 4: Refactor PlainTextContentStorageHandler to use Language object #6448
  • The PlainTextContentStorageHandler class will no longer implement the interface but extend the abstract ContentStorageHandler class. This change will also remove the __construct method, which will then be implemented by the abstract. Changes 5: ContentStorageHandler Abstract #6449
  • The new ::write method will later be moved to the ContentStorageHandler class as an abstract method. ContentStorageHandler will then also get a non-abstract update and create method, which will use the new write method by default. This will add the option for storage handlers to only modify the write method if no further logic is needed for create and update. Changes 10: New MemoryContentStorageHandler #6457

Breaking changes

None

Ready?

  • In-code documentation (wherever needed)
  • Unit tests for fixed bug/feature
  • Tests and checks all pass

For review team

  • Add changes & docs to release notes draft in Notion

@bastianallgeier bastianallgeier requested a review from a team May 6, 2024 10:02
@bastianallgeier bastianallgeier force-pushed the v5/changes/plain-text-handler-refactoring branch 2 times, most recently from 75017a3 to 88a9baf Compare May 6, 2024 13:37
@distantnative
Copy link
Member

@bastianallgeier and we don't need the use case anymore that ::exists() can check whether any language file exists?

@bastianallgeier
Copy link
Member Author

We don't have that case anywhere and if we should ever have it, it should happen one level up. Just imagine that you would want to create your own storage handler one day and you need to implement that kind of logic in your own handler instead of simply defining a call to a single source.

Keep in mind that we have the version class as a layer between model and storage handler anyway. Additional logic should happen there or in the model actions in my opinion.

@distantnative
Copy link
Member

Was just asking, not making an argument for keeping it :)

@bastianallgeier bastianallgeier force-pushed the v5/changes/plain-text-handler-refactoring branch from 88a9baf to 7035712 Compare May 6, 2024 14:26
@bastianallgeier bastianallgeier mentioned this pull request May 6, 2024
6 tasks
Copy link
Member

@lukasbestle lukasbestle left a comment

Choose a reason for hiding this comment

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

The changes in this PR look good.

However I'm also not sure about the removal of language-independent exists(). It was intended for checks of "does the version exist at all". This can then be used for $model->version() to immediately return null.

You are right that it adds complexity to the handler, but it allows the handler to optimize for performance. E.g. a database handler would only have to send a single database query no matter if there is one language or 10. If we implement it in the ContentStorage/Version class, we would still have to loop through all languages there.

Compared to that performance opportunity, I think the added complexity is justified.

@bastianallgeier
Copy link
Member Author

@lukasbestle that's a good point. I wonder though if we should already optimize for that future case or if we keep it as simple as possible for now and then maybe add it later if we really run into an issue.

@lukasbestle lukasbestle force-pushed the v5/changes/plain-text-handler-refactoring branch from 699c762 to b26d23e Compare May 21, 2024 19:10
@lukasbestle lukasbestle marked this pull request as ready for review May 21, 2024 19:10
@lukasbestle
Copy link
Member

My thoughts were around the breaking change that such a later introduction would cause. But as the whole storage interface/abstract is currently internal, we don't really need to worry about that. I just feel like we will forget about it later and not think about reintroducing it when we need it. Since it's just a few lines, I'd vote to keep it. But I'd also be fine to remove it if it makes other stuff simpler down the road.

@bastianallgeier
Copy link
Member Author

With the new ContentStorageHandler abstract, I would vote to move this into its own method. Then a handler can still optimize it, but we can keep it separate to avoid the ambigous logic. In a later step, I already moved over deleteLanguage and touchLanguage from the ContentStorage class and I think adding more specific exist methods would really make sense.

Copy link
Member

@lukasbestle lukasbestle left a comment

Choose a reason for hiding this comment

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

As discussed on Discord, let's leave the nullable language param for exists() out for now. We can still reintroduce it later.

I've reviewed the code of the entire PR now. Nice refactoring work! Just one minor detail left:

src/Content/PlainTextContentStorageHandler.php Outdated Show resolved Hide resolved
@lukasbestle lukasbestle merged commit af1a5a4 into v5/develop May 25, 2024
11 checks passed
@lukasbestle lukasbestle deleted the v5/changes/plain-text-handler-refactoring branch May 25, 2024 14:56
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.

None yet

3 participants