Skip to content

Commit

Permalink
Merge branch 'trunk' into task/stats-insights-diffable-optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
staskus committed Mar 14, 2024
2 parents c8a72a7 + 755fb4a commit 98f4a4d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ _None._

### Bug Fixes

_None._
- Fix a rare crash when accessing date formatter from different threads in StatsRemoteService. [#749]

### Internal Changes

_None._
- Add WP.com theme type information. [#750]

## 14.0.1

Expand Down
1 change: 1 addition & 0 deletions WordPressKit/RemoteTheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@interface RemoteTheme : NSObject

@property (nonatomic, assign) BOOL active;
@property (nonatomic, strong) NSString *type;
@property (nonatomic, strong) NSString *author;
@property (nonatomic, strong) NSString *authorUrl;
@property (nonatomic, strong) NSString *desc;
Expand Down
7 changes: 4 additions & 3 deletions WordPressKit/StatsServiceRemoteV2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ open class StatsServiceRemoteV2: ServiceRemoteWordPressComREST {
public let siteID: Int
private let siteTimezone: TimeZone

private lazy var periodDataQueryDateFormatter: DateFormatter = {
private var periodDataQueryDateFormatter: DateFormatter {
let df = DateFormatter()
df.locale = Locale(identifier: "en_US_POSIX")
df.dateFormat = "yyyy-MM-dd"
return df
}()
}

private lazy var calendarForSite: Calendar = {
var cal = Calendar(identifier: .iso8601)
Expand Down Expand Up @@ -117,8 +117,9 @@ open class StatsServiceRemoteV2: ServiceRemoteWordPressComREST {
return val1
}

wordPressComRestApi.GET(path, parameters: properties, success: { (response, _) in
wordPressComRestApi.GET(path, parameters: properties, success: { [weak self] (response, _) in
guard
let self,
let jsonResponse = response as? [String: AnyObject],
let dateString = jsonResponse["date"] as? String,
let date = self.periodDataQueryDateFormatter.date(from: dateString)
Expand Down
2 changes: 2 additions & 0 deletions WordPressKit/ThemeServiceRemote.m
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ - (RemoteTheme *)themeFromDictionary:(NSDictionary *)dictionary
NSParameterAssert([dictionary isKindOfClass:[NSDictionary class]]);

static NSString* const ThemeActiveKey = @"active";
static NSString* const ThemeTypeKey = @"theme_type";
static NSString* const ThemeAuthorKey = @"author";
static NSString* const ThemeAuthorURLKey = @"author_uri";
static NSString* const ThemeCostPath = @"cost.number";
Expand All @@ -384,6 +385,7 @@ - (RemoteTheme *)themeFromDictionary:(NSDictionary *)dictionary
[self loadLaunchDateForTheme:theme fromDictionary:dictionary];

theme.active = [[dictionary numberForKey:ThemeActiveKey] boolValue];
theme.type = [dictionary stringForKey:ThemeTypeKey];
theme.author = [dictionary stringForKey:ThemeAuthorKey];
theme.authorUrl = [dictionary stringForKey:ThemeAuthorURLKey];
theme.demoUrl = [dictionary stringForKey:ThemeDemoURLKey];
Expand Down
23 changes: 10 additions & 13 deletions WordPressKitTests/Utilities/URLSessionHelperTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,9 @@ class URLSessionHelperTests: XCTestCase {
HTTPStubsResponse(data: "success".data(using: .utf8)!, statusCode: 200, headers: nil)
}

// Create a large file which will be uploaded
let file = try self.createLargeFile(megaBytes: 100)
// Create a large file which will be uploaded. The file size needs to be larger than the hardcoded threshold of
// creating a temporary file for upload.
let file = try self.createLargeFile(megaBytes: 30)
defer {
try? FileManager.default.removeItem(at: file)
}
Expand Down Expand Up @@ -290,8 +291,9 @@ class URLSessionHelperTests: XCTestCase {
HTTPStubsResponse(error: URLError(.networkConnectionLost))
}

// Create a large file which will be uploaded
let file = try self.createLargeFile(megaBytes: 100)
// Create a large file which will be uploaded. The file size needs to be larger than the hardcoded threshold of
// creating a temporary file for upload.
let file = try self.createLargeFile(megaBytes: 30)
defer {
try? FileManager.default.removeItem(at: file)
}
Expand Down Expand Up @@ -331,16 +333,11 @@ class URLSessionHelperTests: XCTestCase {
}

private func createLargeFile(megaBytes: Int) throws -> URL {
let fileManager = FileManager.default
let file = try fileManager.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
let file = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
.appendingPathComponent("large-file-\(UUID().uuidString).txt")
fileManager.createFile(atPath: file.path, contents: nil)

let handle = try FileHandle(forUpdating: file)
for _ in 0..<megaBytes {
handle.write(Data(repeating: 46, count: 1_000_000))
}
try handle.close()
try Data(repeating: 46, count: 1024 * 1000 * megaBytes).write(to: file)

return file
}

Expand All @@ -349,7 +346,7 @@ class URLSessionHelperTests: XCTestCase {
defer { stream.close() }

var hash = SHA256()
let maxLength = 1024
let maxLength = 50 * 1024
var buffer = [UInt8](repeating: 0, count: maxLength)
while stream.hasBytesAvailable {
let bytes = stream.read(&buffer, maxLength: maxLength)
Expand Down

0 comments on commit 98f4a4d

Please sign in to comment.