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

[Gutenberg] Faster editor start #9370

Merged
merged 27 commits into from
Mar 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7763e23
Update mPost via a method to update GB flag too
hypest Jan 26, 2019
e641b66
Cache the Spanned mPost for speed
hypest Jan 26, 2019
722dd8c
Use fast Aztec parsing when appropriate
hypest Feb 7, 2019
c6fdcd6
Point to faster Aztec, update gb-mobile ref too
hypest Feb 7, 2019
4f82a72
Update Aztec, gb-mobile refs
hypest Mar 1, 2019
da13727
Merge branch 'develop' into gb/faster-aztec-updated
hypest Mar 5, 2019
bc7615e
1-deep cache of parsed content
hypest Mar 6, 2019
99244f8
Update gb-mobile ref
hypest Mar 6, 2019
85c060f
Update Aztec ref
hypest Mar 6, 2019
e9f7d0c
Update Aztec hash
hypest Mar 6, 2019
25df6ed
Update Aztec hash
hypest Mar 6, 2019
48b66cf
Compare the content's hash, not the post's
hypest Mar 6, 2019
fbc89ab
Limit line to 120chars
hypest Mar 6, 2019
c7eca95
No need for the 1-deep cache in EditPostActivity
hypest Mar 6, 2019
f2bdaf7
No need for updatePostVar
hypest Mar 6, 2019
8c7a0e9
Some cleanup
hypest Mar 6, 2019
5f43763
Reinstate old interfaces, use parse cache in AztecEditorFragment
hypest Mar 6, 2019
b7dd5d5
Reduce PR diff
hypest Mar 6, 2019
a38544b
Move instance variables to the top
hypest Mar 6, 2019
927cbd6
Less PR diff
hypest Mar 6, 2019
36599c4
Update release notes
hypest Mar 6, 2019
39adc35
Progress bar while waiting for GB
hypest Mar 6, 2019
8db163b
Track the editor mount state, hide progress bar on rotate
hypest Mar 6, 2019
93018d7
Merge branch 'develop' into gb/faster-aztec
hypest Mar 6, 2019
b77a6e5
Update Aztec hash
hypest Mar 7, 2019
110b210
Point to the release Aztec tag
hypest Mar 7, 2019
1ed5eba
Point to the merged gb-mobile commit
hypest Mar 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
12.0
-----
Faster opening of large posts
* Updated Notifications with tabs

11.9
Expand Down
2 changes: 1 addition & 1 deletion libs/editor/WordPressEditor/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
buildscript {

ext {
aztecVersion = 'v1.3.20'
aztecVersion = 'v1.3.21'
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ public AztecLoggingException(Throwable originalException) {

private static boolean mIsToolbarExpanded = false;

// 1-deep cache of html parsed to spans, as a speed optimization instead of parsing the same content again and again
private static int sPostContentHash;
private static Spanned sParsedContentCached;

private boolean mEditorWasPaused = false;
private boolean mHideActionBarOnSoftKeyboardUp = false;

Expand Down Expand Up @@ -1987,7 +1991,7 @@ private static SpannableStringBuilder getCalypsoCompatibleStringBuilder(Context
AztecParser parser) {
SpannableStringBuilder builder = new SpannableStringBuilder();
String cleanSource = Format.removeSourceEditorFormatting(postContent, true);
builder.append(parser.fromHtml(cleanSource, context));
builder.append(parser.parseHtmlForInspection(cleanSource, context));
Format.preProcessSpannedText(builder, true);
return builder;
}
Expand Down Expand Up @@ -2102,7 +2106,7 @@ public static boolean hasMediaItemsMarkedFailed(Context context, @NonNull String
private static boolean hasMediaItemsMarkedWithTag(Context context, @NonNull String postContent, String tag) {
// fill in Aztec with the post's content
AztecParser parser = getAztecParserWithPlugins();
Spanned content = parser.fromHtml(postContent, context);
Spanned content = parseContent(context, parser, postContent);

// get all items with the class in the "tag" param
AztecText.AttributePredicate uploadingPredicate = getPredicateWithClass(tag);
Expand Down Expand Up @@ -2141,7 +2145,7 @@ private static List<String> getMediaMarkedAsClassInPostContent(Context context,
ArrayList<String> mediaMarkedUploading = new ArrayList<>();
// fill in Aztec with the post's content
AztecParser parser = getAztecParserWithPlugins();
Spanned content = parser.fromHtml(postContent, context);
Spanned content = parseContent(context, parser, postContent);
AztecText.AttributePredicate uploadingPredicate = getPredicateWithClass(classToUse);
for (Attributes attrs : getAllElementAttributes(content, uploadingPredicate)) {
String itemId = attrs.getValue(ATTR_ID_WP);
Expand All @@ -2152,6 +2156,20 @@ private static List<String> getMediaMarkedAsClassInPostContent(Context context,
return mediaMarkedUploading;
}

public static Spanned parseContent(Context context, AztecParser parser, @NonNull String postContent) {
// parsing is an expensive operation (especially if the content is big) so, return previous result if matching.
if (sParsedContentCached != null && postContent.hashCode() == sPostContentHash) {
return new SpannableString(sParsedContentCached);
}

// cache the post's content hash to compare next time
sPostContentHash = postContent.hashCode();

// fill in Aztec with the post's content
sParsedContentCached = parser.parseHtmlForInspection(postContent, context);
return sParsedContentCached;
}

public void setMediaToFailed(@NonNull String mediaId) {
AztecText.AttributePredicate localMediaIdPredicate = MediaPredicate.getLocalMediaIdPredicate(mediaId);
// we should be obtaining just one span for this media Id predicate, but just in case something
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
Expand Down Expand Up @@ -55,6 +56,7 @@ public class GutenbergEditorFragment extends EditorFragmentAbstract implements
EditorMediaUploadListener,
IHistoryListener {
private static final String KEY_HTML_MODE_ENABLED = "KEY_HTML_MODE_ENABLED";
private static final String KEY_EDITOR_DID_MOUNT = "KEY_EDITOR_DID_MOUNT";
private static final String ARG_IS_NEW_POST = "param_is_new_post";
private static final String ARG_LOCALE_SLUG = "param_locale_slug";

Expand All @@ -77,6 +79,8 @@ public class GutenbergEditorFragment extends EditorFragmentAbstract implements

private boolean mIsNewPost;

private boolean mEditorDidMount;

public static GutenbergEditorFragment newInstance(String title,
String content,
boolean isNewPost,
Expand Down Expand Up @@ -193,6 +197,7 @@ public void onCreate(Bundle savedInstanceState) {

if (savedInstanceState != null) {
mHtmlModeEnabled = savedInstanceState.getBoolean(KEY_HTML_MODE_ENABLED);
mEditorDidMount = savedInstanceState.getBoolean(KEY_EDITOR_DID_MOUNT);
}
}

Expand Down Expand Up @@ -239,7 +244,16 @@ public void onQueryCurrentProgressForUploadingMedia() {
new OnEditorMountListener() {
@Override
public void onEditorDidMount(boolean hasUnsupportedBlocks) {
mEditorDidMount = true;
mEditorFragmentListener.onEditorFragmentContentReady(hasUnsupportedBlocks);

// Hide the progress bar when editor is ready
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
setEditorProgressBarVisibility(!mEditorDidMount);
}
});
}
}
);
Expand Down Expand Up @@ -273,6 +287,12 @@ public void run() {
return view;
}

@Override public void onResume() {
super.onResume();

setEditorProgressBarVisibility(!mEditorDidMount);
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults) {
Expand All @@ -281,6 +301,12 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
}
}

private void setEditorProgressBarVisibility(boolean shown) {
if (isAdded() && getView() != null) {
getView().findViewById(R.id.editor_progress).setVisibility(shown ? View.VISIBLE : View.GONE);
}
}

public void resetUploadingMediaToFailed(Set<Integer> failedMediaIds) {
// get all media failed for this post, and represent it on tje UI
if (failedMediaIds != null && !failedMediaIds.isEmpty()) {
Expand Down Expand Up @@ -402,6 +428,7 @@ public void onAttach(Activity activity) {
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putBoolean(KEY_HTML_MODE_ENABLED, mHtmlModeEnabled);
outState.putBoolean(KEY_EDITOR_DID_MOUNT, mEditorDidMount);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,12 @@
android:layout_width="match_parent"
android:background="@color/white"
android:focusable="false"
android:focusableInTouchMode="true"/>
android:focusableInTouchMode="true">

<ProgressBar
android:id="@+id/editor_progress"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"/>
</FrameLayout>