@@ -42,11 +42,14 @@ actor EditorService {
4242 self . siteURL = siteURL
4343 self . urlSession = urlSession
4444
45- self . storeURL = URL . applicationDirectory
46- . appendingPathComponent ( " GutenbergKit " , isDirectory: true )
45+ self . storeURL = EditorService . rootURL
4746 . appendingPathComponent ( siteURL. sha1, isDirectory: true )
4847 }
4948
49+ private static var rootURL : URL {
50+ URL . applicationDirectory. appendingPathComponent ( " GutenbergKit " , isDirectory: true )
51+ }
52+
5053 /// Set up the editor for the given site.
5154 ///
5255 /// - warning: The request make take a significant amount of time the first
@@ -309,15 +312,18 @@ actor EditorService {
309312 return ( true , size ?? 0 )
310313 }
311314
315+ let startTime = CFAbsoluteTimeGetCurrent ( )
312316 let ( downloadedURL, response) = try await urlSession. download ( from: url)
317+ let downloadTime = CFAbsoluteTimeGetCurrent ( ) - startTime
318+
313319 if let status = ( response as? HTTPURLResponse ) ? . statusCode, ( 200 ..< 300 ) . contains ( status) {
314320 let size = try ? FileManager . default. attributesOfItem ( atPath: downloadedURL. path) [ . size] as? Int64 ?? 0
315321 do {
316322 try FileManager . default. moveItem ( at: downloadedURL, to: localURL)
317323 } catch {
318324 log ( . error, " Failed to move downloaded assets \( downloadedURL) \( localURL) " )
319325 }
320- log ( . debug, " Downloaded asset: \( url. lastPathComponent) ( \( size ?? 0 ) bytes) " )
326+ log ( . debug, " Downloaded asset: \( url. lastPathComponent) ( \( size ?? 0 ) bytes) in \( String ( format : " %.2f " , downloadTime ) ) s " )
321327 return ( false , size ?? 0 )
322328 } else {
323329 log ( . error, " Received unexpected HTTP response for URL: \( url) " )
@@ -347,11 +353,9 @@ actor EditorService {
347353
348354 /// Deletes all cached editor data for all sites
349355 static func deleteAllData( ) throws {
350- let rootURL = URL . documentsDirectory. appendingPathComponent ( " GutenbergKit " , isDirectory: true )
351- guard FileManager . default. fileExists ( atPath: rootURL. path) else {
352- return
356+ if FileManager . default. fileExists ( atPath: EditorService . rootURL. path ( ) ) {
357+ try FileManager . default. removeItem ( at: EditorService . rootURL)
353358 }
354- try FileManager . default. removeItem ( at: rootURL)
355359 }
356360
357361 /// Generates a cached filename from an asset URL using SHA256 hash
0 commit comments