Skip to content

Commit

Permalink
Prewarm post page and planet CID on ipfs2.eth.limo
Browse files Browse the repository at this point in the history
  • Loading branch information
livid committed Nov 23, 2023
1 parent adfa7f2 commit 0c36e63
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Planet/Entities/MyArticleModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ class MyArticleModel: ArticleModel, Codable {
func prewarm() async {
guard let postURL = browserURL else { return }
let articleJSONURL = postURL.appendingPathComponent("article.json")
// post page: /UUID/ or /slug/
do {
debugPrint("About to prewarm \(planet.name) post: \(postURL)")
let (postData, _) = try await URLSession.shared.data(from: postURL)
Expand All @@ -377,8 +378,9 @@ class MyArticleModel: ArticleModel, Codable {
catch {
debugPrint("Failed to prewarm \(planet.name) post \(postURL): \(error)")
}
// metadata: /UUID/article.json or /slug/article.json
do {
debugPrint("About to prewarm \(planet.name) post: \(articleJSONURL)")
debugPrint("About to prewarm \(planet.name) post metadata: \(articleJSONURL)")
let (articleJSONData, _) = try await URLSession.shared.data(from: articleJSONURL)
debugPrint("Prewarmed \(planet.name) post metadata: \(articleJSONData.count) bytes")
}
Expand Down
14 changes: 14 additions & 0 deletions Planet/Entities/MyPlanetModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ class MyPlanetModel: Equatable, Hashable, Identifiable, ObservableObject, Codabl
return URL(string: "https://\(ipns).ipfs2.eth.limo/")
}

var cidURL: URL? {
guard let cid = self.lastPublishedCID else { return nil }
return URL(string: "https://\(cid).ipfs2.eth.limo/")
}

func hash(into hasher: inout Hasher) {
hasher.combine(id)
hasher.combine(name)
Expand Down Expand Up @@ -1650,6 +1655,15 @@ class MyPlanetModel: Equatable, Hashable, Identifiable, ObservableObject, Codabl
catch {
debugPrint("Failed to prewarm \(name) \(planetJSONURL): \(error)")
}
guard let cidURL = cidURL else { return }
do {
debugPrint("About to prewarm \(name) CID: \(cidURL)")
let (cidData, _) = try await URLSession.shared.data(from: cidURL)
debugPrint("Prewarmed \(name) CID: \(cidData.count) bytes")
}
catch {
debugPrint("Failed to prewarm \(name) \(cidURL) CID: \(error)")
}
}

/// Send pin request to Pinnable API if enabled
Expand Down
2 changes: 1 addition & 1 deletion Planet/versioning.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CURRENT_PROJECT_VERSION = 1798
CURRENT_PROJECT_VERSION = 1799

0 comments on commit 0c36e63

Please sign in to comment.