Skip to content

Commit

Permalink
Remove lazy loading:
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Jan 10, 2025
1 parent 7599361 commit 5879f6a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 60 deletions.
1 change: 1 addition & 0 deletions WordPress/Classes/Models/Blog/BlogSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ open class BlogSettings: NSManagedObject {

/// Jetpack Setting: lazy load images.
///
@available(*, deprecated)
@NSManaged var jetpackLazyLoadImages: Bool

// MARK: - Discussion
Expand Down
24 changes: 0 additions & 24 deletions WordPress/Classes/Services/BlogJetpackSettingsService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,29 +142,6 @@ struct BlogJetpackSettingsService {
)
}

func updateJetpackLazyImagesModuleSettingForBlog(_ blog: Blog, success: @escaping () -> Void, failure: @escaping (Error?) -> Void) {
guard let blogSettings = blog.settings else {
failure(nil)
return
}

let isActive = blogSettings.jetpackLazyLoadImages
updateJetpackModuleActiveSettingForBlog(
blog,
module: BlogJetpackSettingsServiceRemote.Keys.lazyLoadImages,
active: isActive,
success: {
self.coreDataStack.performAndSave({ context in
guard let blogSettingsInContext = Blog.lookup(withObjectID: blog.objectID, in: context)?.settings else {
return
}
blogSettingsInContext.jetpackLazyLoadImages = isActive
}, completion: success, on: .main)
},
failure: failure
)
}

func updateJetpackServeImagesFromOurServersModuleSettingForBlog(_ blog: Blog, success: @escaping () -> Void, failure: @escaping (Error?) -> Void) {
guard let blogSettings = blog.settings else {
failure(nil)
Expand Down Expand Up @@ -235,7 +212,6 @@ private extension BlogJetpackSettingsService {
}

func updateJetpackModulesSettings(_ settings: BlogSettings, remoteSettings: RemoteBlogJetpackModulesSettings) {
settings.jetpackLazyLoadImages = remoteSettings.lazyLoadImages
settings.jetpackServeImagesFromOurServers = remoteSettings.serveImagesFromOurServers
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ open class JetpackSpeedUpSiteSettingsViewController: UITableViewController {

open override func viewDidLoad() {
super.viewDidLoad()

title = NSLocalizedString("Speed up your site", comment: "Title for the Speed up your site Settings Screen")
ImmuTable.registerRows([SwitchRow.self], tableView: tableView)
WPStyleGuide.configureColors(view: view, tableView: tableView)
Expand All @@ -51,34 +52,18 @@ open class JetpackSpeedUpSiteSettingsViewController: UITableViewController {
}

func tableViewModel() -> ImmuTable {

let serveImagesFromOurServers = SwitchRow(title: NSLocalizedString("Serve images from our servers",
comment: "Title for the Serve images from our servers setting"),
value: self.settings.jetpackServeImagesFromOurServers,
onChange: self.serveImagesFromOurServersValueChanged())

let lazyLoadImages = SwitchRow(title: NSLocalizedString("\"Lazy-load\" images",
comment: "Title for the lazy load images setting"),
value: self.settings.jetpackLazyLoadImages,
onChange: self.lazyLoadImagesValueChanged())
let serveImagesFromOurServers = SwitchRow(
title: NSLocalizedString("Serve images from our servers",
comment: "Title for the Serve images from our servers setting"),
value: self.settings.jetpackServeImagesFromOurServers,
onChange: self.serveImagesFromOurServersValueChanged())

return ImmuTable(sections: [
ImmuTableSection(
headerText: "",
rows: [serveImagesFromOurServers],
footerText: NSLocalizedString("Jetpack will optimize your images and serve them from the server " +
"location nearest to your visitors. Using our global content delivery " +
"network will boost the loading speed of your site.",
comment: "Footer for the Serve images from our servers setting")),

ImmuTableSection(
headerText: "",
rows: [lazyLoadImages],
footerText: NSLocalizedString("Improve your site's speed by only loading images visible on the screen. " +
"New images will load just before they scroll into view. This prevents " +
"viewers from having to download all the images on a page all at once, " +
"even ones they can't see.",
comment: "Footer for the Serve images from our servers setting")),
footerText: NSLocalizedString("Jetpack will optimize your images and serve them from the server location nearest to your visitors. Using our global content delivery network will boost the loading speed of your site.", comment: "Footer for the Serve images from our servers setting")
)
])
}

Expand All @@ -98,19 +83,6 @@ open class JetpackSpeedUpSiteSettingsViewController: UITableViewController {
}
}

fileprivate func lazyLoadImagesValueChanged() -> (_ newValue: Bool) -> Void {
return { [unowned self] newValue in
self.settings.jetpackLazyLoadImages = newValue
self.reloadViewModel()
WPAnalytics.trackSettingsChange("jetpack_speed_up_site", fieldName: "lazy_load_images", value: newValue as Any)
self.service.updateJetpackLazyImagesModuleSettingForBlog(self.blog,
success: {},
failure: { [weak self] (_) in
self?.refreshSettingsAfterSavingError()
})
}
}

// MARK: - Persistance

fileprivate func refreshSettings() {
Expand Down

0 comments on commit 5879f6a

Please sign in to comment.