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

Prefetch xpost suggestions in Gutenberg #15562

Merged
merged 1 commit into from
Dec 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions WordPress/Classes/Services/SiteSuggestionService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ class SiteSuggestionService {
}
}

/**
If no suggestions already in Core Data, fetch them from the network and store them in Core Data.
@param blog The blog/site to prefetch suggestions for
*/
func prefetchSuggestions(for blog: Blog) {
let persistedSuggestions = retrievePersistedSuggestions(for: blog)
if persistedSuggestions == nil || persistedSuggestions?.isEmpty == true {
fetchAndPersistSuggestions(for: blog, completion: { _ in})
}
}

/**
Performs a REST API request for the given blog.
Persists response objects to Core Data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ class GutenbergViewController: UIViewController, PostEditor {
}, failure: { (error) in
DDLogError("Error syncing JETPACK: \(String(describing: error))")
})

SiteSuggestionService.shared.prefetchSuggestions(for: self.post.blog)
}

override func viewWillAppear(_ animated: Bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ extension PostEditor where Self: UIViewController {
}
self.recreatePostRevision(in: blog)
self.mediaLibraryDataSource = MediaLibraryPickerDataSource(post: self.post)

if self.editorSession.currentEditor == .gutenberg {
SiteSuggestionService.shared.prefetchSuggestions(for: self.post.blog)
}
}

let dismissHandler: BlogSelectorDismissHandler = {
Expand Down