Skip to content

Commit

Permalink
Merge pull request #231 from kmcbride/maintenance
Browse files Browse the repository at this point in the history
Misc maintenance
  • Loading branch information
gitrema authored Mar 22, 2023
2 parents e967626 + ff97f24 commit faa89a8
Show file tree
Hide file tree
Showing 146 changed files with 334 additions and 337 deletions.
2 changes: 1 addition & 1 deletion Framework/SPTDataLoader.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2015-2022 Spotify AB
Copyright 2015-2023 Spotify AB
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion Sources/SPTDataLoader/NSDictionary+HeaderSize.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2015-2022 Spotify AB
Copyright 2015-2023 Spotify AB
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
6 changes: 3 additions & 3 deletions Sources/SPTDataLoader/NSDictionary+HeaderSize.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2015-2022 Spotify AB
Copyright 2015-2023 Spotify AB
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,13 +27,13 @@ - (NSInteger)spt_byteSizeOfHeaders
if (![key isKindOfClass:[NSString class]]) {
continue;
}

NSString *keyString = (NSString *)key;
id object = self[keyString];
if (![object isKindOfClass:[NSString class]]) {
continue;
}

NSString *objectString = (NSString *)object;
headerSize += [keyString dataUsingEncoding:NSUTF8StringEncoding].length;
headerSize += [@": \n" dataUsingEncoding:NSUTF8StringEncoding].length;
Expand Down
12 changes: 6 additions & 6 deletions Sources/SPTDataLoader/SPTDataLoader.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2015-2022 Spotify AB
Copyright 2015-2023 Spotify AB
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -116,13 +116,13 @@ - (void)removeRequest:(SPTDataLoaderRequest *)request
@synchronized(self.cancellationTokens) {
[self.cancellationTokens addObject:cancellationToken];
}

@synchronized(self.requests) {
[self.requests addObject:copiedRequest];
}

[self.requestResponseHandlerDelegate requestResponseHandler:self performRequest:copiedRequest];

return cancellationToken;
}

Expand Down Expand Up @@ -171,7 +171,7 @@ - (void)successfulResponse:(SPTDataLoaderResponse *)response
if (![self isRequestExpected:response.request]) {
return;
}

[self executeDelegateBlock: ^{
[self.delegate dataLoader:self didReceiveSuccessfulResponse:response];
}];
Expand Down Expand Up @@ -215,7 +215,7 @@ - (void)receivedDataChunk:(NSData *)data forResponse:(SPTDataLoaderResponse *)re

// Do not send a callback if the request doesn't support it
NSAssert(response.request.chunks, @"The data loader is receiving a data chunk for a response that doesn't support data chunks");

BOOL didReceiveDataChunkSelectorExists = [self.delegate respondsToSelector:@selector(dataLoader:didReceiveDataChunk:forResponse:)];
if (didReceiveDataChunkSelectorExists) {
[self executeDelegateBlock: ^{
Expand All @@ -234,7 +234,7 @@ - (void)receivedInitialResponse:(SPTDataLoaderResponse *)response
if (!response.request.chunks) {
return;
}

if ([self.delegate respondsToSelector:@selector(dataLoader:didReceiveInitialResponse:)]) {
[self executeDelegateBlock: ^{
[self.delegate dataLoader:self didReceiveInitialResponse:response];
Expand Down
2 changes: 1 addition & 1 deletion Sources/SPTDataLoader/SPTDataLoaderBlockWrapper.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2015-2022 Spotify AB
Copyright 2015-2023 Spotify AB
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2015-2022 Spotify AB
Copyright 2015-2023 Spotify AB
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2015-2022 Spotify AB
Copyright 2015-2023 Spotify AB
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2015-2022 Spotify AB
Copyright 2015-2023 Spotify AB
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2015-2022 Spotify AB
Copyright 2015-2023 Spotify AB
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2015-2022 Spotify AB
Copyright 2015-2023 Spotify AB
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -42,7 +42,7 @@ - (instancetype)initWithDelegate:(id<SPTDataLoaderCancellationTokenDelegate>)del
_delegate = delegate;
_objectToCancel = cancelObject;
}

return self;
}

Expand All @@ -57,9 +57,9 @@ - (void)cancel
if (self.cancelled) {
return;
}

[self.delegate cancellationTokenDidCancel:self];

self.cancelled = YES;
}

Expand Down
16 changes: 8 additions & 8 deletions Sources/SPTDataLoader/SPTDataLoaderExponentialTimer.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2015-2022 Spotify AB
Copyright 2015-2023 Spotify AB
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -88,22 +88,22 @@ - (void)reset
- (NSTimeInterval)calculateNext
{
NSTimeInterval nextTime = self.timeInterval * self.growFactor;

if (nextTime > self.maxTime) {
nextTime = self.maxTime;
}

if (self.jitter < 0.0001) {
self.timeInterval = nextTime;
} else {
const double sigma = self.jitter * nextTime;
self.timeInterval = [self.class normalWithMu:nextTime sigma:sigma];
}

if (self.timeInterval > self.maxTime) {
self.timeInterval = self.maxTime;
}

return self.timeInterval;
}

Expand All @@ -119,7 +119,7 @@ - (NSTimeInterval)timeIntervalAndCalculateNext

#define EXPT_MODULO ((u_int32_t)RAND_MAX)
#define EXPT_MODULO_F64 ((double)(EXPT_MODULO))
NS_INLINE double SPTExptRandom()
NS_INLINE double SPTExptRandom(void)
{
// We need [0, 1) interval
return arc4random_uniform(EXPT_MODULO);
Expand All @@ -140,12 +140,12 @@ + (NSTimeInterval)normalWithMu:(double)mu sigma:(double)sigma
const double b = 1.0 - (SPTExptRandom() / EXPT_MODULO_F64);
const double c = 1.7155277699214135 * (a - 0.5) / b;
const double d = c * c / 4.0;

if (d <= -1.0 * log(b)) {
return mu + c * sigma;
}
}

return mu + 2.0 * sigma * (SPTExptRandom() / EXPT_MODULO_F64);
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/SPTDataLoader/SPTDataLoaderFactory+Private.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2015-2022 Spotify AB
Copyright 2015-2023 Spotify AB
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
14 changes: 7 additions & 7 deletions Sources/SPTDataLoader/SPTDataLoaderFactory.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2015-2022 Spotify AB
Copyright 2015-2023 Spotify AB
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -60,7 +60,7 @@ - (instancetype)initWithRequestResponseHandlerDelegate:(nullable id<SPTDataLoade
authoriser.delegate = self;
}
}

return self;
}

Expand Down Expand Up @@ -108,7 +108,7 @@ - (void)failedResponse:(SPTDataLoaderResponse *)response
return;
}
}

id<SPTDataLoaderRequestResponseHandler> requestResponseHandler = nil;
@synchronized(self.requestToRequestResponseHandler) {
requestResponseHandler = [self.requestToRequestResponseHandler objectForKey:response.request];
Expand Down Expand Up @@ -161,7 +161,7 @@ - (BOOL)shouldAuthoriseRequest:(SPTDataLoaderRequest *)request
return YES;
}
}

return NO;
}

Expand Down Expand Up @@ -192,11 +192,11 @@ - (void)requestResponseHandler:(id<SPTDataLoaderRequestResponseHandler>)requestR
if (self.offline) {
request.cachePolicy = NSURLRequestReturnCacheDataDontLoad;
}

@synchronized(self.requestToRequestResponseHandler) {
[self.requestToRequestResponseHandler setObject:requestResponseHandler forKey:request];
}

// Add an absolute timeout for responses
if (request.timeout > 0.0) {
__weak __typeof(self) weakSelf = self;
Expand All @@ -215,7 +215,7 @@ - (void)requestResponseHandler:(id<SPTDataLoaderRequestResponseHandler>)requestR
[strongSelf failedResponse:response];
});
}

[self.requestResponseHandlerDelegate requestResponseHandler:self performRequest:request];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2015-2022 Spotify AB
Copyright 2015-2023 Spotify AB
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
3 changes: 1 addition & 2 deletions Sources/SPTDataLoader/SPTDataLoaderRateLimiter+Private.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2015-2022 Spotify AB
Copyright 2015-2023 Spotify AB
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,4 +30,3 @@ NS_ASSUME_NONNULL_BEGIN
@end

NS_ASSUME_NONNULL_END

14 changes: 7 additions & 7 deletions Sources/SPTDataLoader/SPTDataLoaderRateLimiter.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2015-2022 Spotify AB
Copyright 2015-2023 Spotify AB
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -55,14 +55,14 @@ - (instancetype)initWithDefaultRequestsPerSecond:(double)requestsPerSecond
_serviceEndpointLastExecution = [NSMutableDictionary new];
_serviceEndpointRetryAt = [NSMutableDictionary new];
}

return self;
}

- (NSTimeInterval)earliestTimeUntilRequestCanBeExecuted:(SPTDataLoaderRequest *)request
{
NSString *serviceKey = [self serviceKeyFromURL:request.URL];

// First check if we are not accepting requests until a certain time (i.e. Retry-after header)
CFAbsoluteTime currentTime = self.timeProvider.currentTime;
CFAbsoluteTime retryAtTime = 0.0;
Expand All @@ -72,7 +72,7 @@ - (NSTimeInterval)earliestTimeUntilRequestCanBeExecuted:(SPTDataLoaderRequest *)
if (currentTime < retryAtTime) {
return retryAtTime - currentTime;
}

// Next check that our rate limit is being respected
double requestsPerSecond = [self requestsPerSecondForServiceKey:serviceKey];
CFAbsoluteTime lastExecution = 0.0;
Expand All @@ -90,7 +90,7 @@ - (NSTimeInterval)earliestTimeUntilRequestCanBeExecuted:(SPTDataLoaderRequest *)
if (timeInterval < 0.0) {
timeInterval = 0.0;
}

return timeInterval;
}

Expand All @@ -100,7 +100,7 @@ - (void)executedRequest:(SPTDataLoaderRequest *)request
if (!serviceKey) {
return;
}

@synchronized(self.serviceEndpointLastExecution) {
self.serviceEndpointLastExecution[serviceKey] = @(self.timeProvider.currentTime);
}
Expand All @@ -126,7 +126,7 @@ - (void)setRetryAfter:(NSTimeInterval)absoluteTime forURL:(NSURL *)URL
if (!URL) {
return;
}

@synchronized(self.serviceEndpointRetryAt) {
self.serviceEndpointRetryAt[[self serviceKeyFromURL:URL]] = @(absoluteTime);
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SPTDataLoader/SPTDataLoaderRequest+Private.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2015-2022 Spotify AB
Copyright 2015-2023 Spotify AB
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit faa89a8

Please sign in to comment.