-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Move purgeMediaToPostAssociationIfNotInPostAnymore to UseCase #10798
Conversation
...ain/java/org/wordpress/android/ui/posts/editor/media/CleanUpMediaToPostAssociationUseCase.kt
Outdated
Show resolved
Hide resolved
...java/org/wordpress/android/ui/posts/editor/media/CleanUpMediaToPostAssociationUseCaseTest.kt
Outdated
Show resolved
Hide resolved
...java/org/wordpress/android/ui/posts/editor/media/CleanUpMediaToPostAssociationUseCaseTest.kt
Outdated
Show resolved
Hide resolved
...java/org/wordpress/android/ui/posts/editor/media/CleanUpMediaToPostAssociationUseCaseTest.kt
Outdated
Show resolved
Hide resolved
You can test the changes on this Pull Request by downloading the APK here. |
* | ||
*/ | ||
@Reusable | ||
class AztecEditorFragmentStaticWrapper @Inject constructor(private val appContext: Context) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've created something similar in my PR, we need to think about it when we merge the PRs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR is already merged. Do you think you can now merge the 2 classes? :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@planarvoid Hmm, I checked develop yesterday and I couldn't find AztecEditorWrapper
there. It seems we merged the PR into the master_edit_post_activity_refactoring
branch but this PR targets develop.
import org.wordpress.android.ui.prefs.AppPrefsWrapper | ||
|
||
@InternalCoroutinesApi | ||
@RunWith(Parameterized::class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😍
if (!allMedia.isEmpty()) { | ||
HashSet<MediaModel> mediaToDeleteAssociationFor = new HashSet<>(); | ||
for (MediaModel media : allMedia) { | ||
if (useAztec) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hypest I'm a bit confused by this code and I was wondering if you could bring some light into it.
Both AppPrefs.isAztecEditorEnabled();
and AppPrefs.isGutenbergEditorEnabled();
always return true
. Which means we always perform the search for media using AztecEditorFragment.isMediaInPostBody(
and we never use PostUtils.isMediaInGutenbergPostBody
. Do you think it's desired behaviour and it's just a preparation for the time when we remove Aztec from the app or it's a bug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be a combination of "prepare for removing Aztec" and a bug.
It makes sense to have the different conditionals (in preparation of removing Aztec) but the Gutenberg check should probably come first, I think. I'm not super sure though so, let's also ping @mzorz who wrote this to confirm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a "prepare for removing Aztec" glitch, which then introduced other bugs.
let's also ping @mzorz who wrote this to confirm.
Not exactly :D looks like it was actually you @hypest 😄, but I certainly appreciate being considered as someone who participated in building this 🙇 (jokes aside I was definitely involved in these conversations about opt-in and such so, thanks for the ping)
I had a look back in code's history, to make sense about existing code and past decisions (git blame is my friend). A bit of searching shows where this comes from:
- This is where both
isGutenbergEditorEnabled()
andisAztecEditorEnabled()
are hardcoded to returntrue
630f454 - That commit belongs to this PR Enable Gutenberg for all and hide legacy editors options #9208
That explains why / what was done, but of course history doesn't say much about future plans, so deferring back to @hypest here looks like the right way to go.
What to do
IMO, regarding that piece of code itself (code in purgeMediaToPostAssociationsIfNotInPostAnymore()
), we should make sure both AztecEditorFragment.isMediaInPostBody()
runs when in a non-Gutenberg Post, and also make sure that PostUtils.isMediaInGutenbergPostBody()
gets run for Gutenberg-block-containing Posts, which apparently is not the case anymore since that commit up there.
It makes sense to have the different conditionals (in preparation of removing Aztec) but the Gutenberg check should probably come first, I think.
In principle, this sounds like a good approach (inverting the if
checks to first check for gutenberg, and else if
check Aztec). Needless to say, all of these cases should be hunted down and scrutinized thoroughly though, to make sure code does what we want it t do.
We should also care checking for other places where these checks are made, for example here
I'd also suggest doing a search for both keywords as these throw various places where conditions shown won't be met and are worth taking a deep look into (and fix them), could be in a separate PR but most probably still within the context of this migration to UseCase (not sure what the plans are but I'd tend to think this is important)
Also note
Another thing worth noting in the context of evaluating this method and its purpose: the actual purge code there (method purgeMediaToPostAssociationsIfNotInPostAnymore()
) was introduced in fe89892, belonging to this PR #7081, it was needed in case we had lost MediaUploadModel
instances in FluxC that are no longer valid (for example when an un unexpected close happened during an upload for an image in a Post), leaving things in an inconsistent state (you can check the usages for ClearMediaPayload
here)
Hope that helps clarify things a bit!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️ ❤️ ❤️ Thanks for such a detailed elaboration @mzorz !!
we should make sure both AztecEditorFragment.isMediaInPostBody() runs when in a non-Gutenberg Post, and also make sure that PostUtils.isMediaInGutenbergPostBody() gets run for Gutenberg-block-containing Posts
Do you think we should check if the post itself contains a gutenberg block using (
WordPress-Android/WordPress/src/main/java/org/wordpress/android/ui/posts/PostUtils.java
Line 391 in a29f28c
public static boolean contentContainsGutenbergBlocks(String postContent) { |
if(contentContainsGutenbergBlocks ) PostUtils.isMediaInGutenbergPostBody() else AztecEditorFragment.isMediaInPostBody()
and not use isAztecEditorEnabled/isGutenbergEditorEnabled at all?
We should also care checking for other places where these checks are made, for example here
I'll do my best checking those as well, but I'm not sure I have enough context to make the right decision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for such a detailed elaboration
yw! ❤️
so basically replace the if with if(contentContainsGutenbergBlocks ) PostUtils.isMediaInGutenbergPostBody() else AztecEditorFragment.isMediaInPostBody() and not use isAztecEditorEnabled/isGutenbergEditorEnabled at all?
That sounds good to me! 👍
We should also care checking for other places where these checks are made, for example here
I'll do my best checking those as well, but I'm not sure I have enough context to make the right decision.
Understood @malinajirka, your willingness is appreciated, maybe this belongs more in the realm of Gutenberg team? I can help checking your code with @hypest (or someone @hypest may like to point to) if you need 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've created a separate issue for the audit - #10881. I'll look into it this or next week.
Howdy folks! I'm freezing |
Thanks @planarvoid! I think it's ready for another round. |
We're freezing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, the purge runs (I tested it with the debugger) 👍
Merge instruction:
Moves purgeMedia.. into its own useCase and introduces unit tests.
To test:
PR submission checklist:
I have considered adding unit tests where possible.
I have considered if this change warrants user-facing release notes and have added them to
RELEASE-NOTES.txt
if necessary.