Skip to content

Commit

Permalink
Avoid sending too many requests at the same time while downloading fo…
Browse files Browse the repository at this point in the history
…lder
  • Loading branch information
poetwang committed Jul 3, 2016
1 parent 38a1d87 commit 5301363
Show file tree
Hide file tree
Showing 25 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion SeafProvider/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<string>2</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
Expand Down
2 changes: 1 addition & 1 deletion SeafProviderFileProvider/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<string>2</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
Expand Down
14 changes: 9 additions & 5 deletions common/SeafConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,6 @@ - (NSURLRequest *)buildRequest:(NSString *)url method:(NSString *)method form:(N
if (self.token)
[request setValue:[NSString stringWithFormat:@"Token %@", self.token] forHTTPHeaderField:@"Authorization"];

Debug("Request: %@", request.URL);
return request;
}

Expand All @@ -633,6 +632,8 @@ - (void)sendRequestAsync:(NSString *)url method:(NSString *)method form:(NSStrin
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, id JSON, NSError *error))failure
{
NSURLRequest *request = [self buildRequest:url method:method form:form];
Debug("Request: %@", request.URL);

NSURLSessionDataTask *task = [_sessionMgr dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) {
NSHTTPURLResponse *resp = (NSHTTPURLResponse *)response;
if (error) {
Expand Down Expand Up @@ -1339,14 +1340,17 @@ - (void)clearUploadingVideos
- (void)downloadDir:(SeafDir *)dir
{
[dir downloadContentSuccess:^(SeafDir *dir) {
Debug("dir %@ items: %d", dir.path, dir.items.count);
long delay = 1;
for (SeafBase *item in dir.items) {
delay += 1;
if ([item isKindOfClass:[SeafFile class]]) {
SeafFile *file = (SeafFile *)item;
Debug("download file: %@, %@", item.repoId, item.path );
[SeafGlobal.sharedObject addDownloadTask:file];
Debug("download file: %@, %@ after %ld ms", item.repoId, item.path, delay);
[SeafGlobal.sharedObject performSelector:@selector(addDownloadTask:) withObject:file afterDelay:delay];
} else if ([item isKindOfClass:[SeafDir class]]) {
Debug("download dir: %@, %@", item.repoId, item.path );
[self downloadDir:(SeafDir *)item];
Debug("download dir: %@, %@ after %ld ms", item.repoId, item.path, delay);
[self performSelector:@selector(downloadDir:) withObject:(SeafDir *)item afterDelay:delay];
}
}
} failure:^(SeafDir *dir) {
Expand Down
1 change: 1 addition & 0 deletions common/SeafFile.m
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ - (void)downloadThumb
int size = THUMB_SIZE * (int)[[UIScreen mainScreen] scale];
NSString *thumburl = [NSString stringWithFormat:API_URL"/repos/%@/thumbnail/?size=%d&p=%@", self.repoId, size, self.path.escapedUrl];
NSURLRequest *downloadRequest = [connection buildRequest:thumburl method:@"GET" form:nil];
Debug("Request: %@", downloadRequest.URL);
NSString *target = [self thumbPath:self.oid];
@synchronized (self) {
if (_thumbtask) return;
Expand Down
2 changes: 1 addition & 1 deletion seafile/SeafFileViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ - (void)refreshView
[self noneSelected:NO];
}
if (_directory && !_directory.hasCache) {
Debug("no cache, load from server.");
Debug("no cache, load %@ from server.", _directory.path);
[self showLoadingView];
self.state = STATE_LOADING;
}
Expand Down
1 change: 1 addition & 0 deletions seafile/StartViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ - (void)checkSelectAccount:(SeafConnection *)conn completeHandler:(void (^)(bool
BOOL ret = [self selectAccount:conn];
return handler(ret);
}
Debug("verify touchId for %@ %@", conn.address, conn.username);
[self checkTouchId:^(bool success) {
if (success) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.), dispatch_get_main_queue(), ^{
Expand Down
Binary file modified seafile/ca.lproj/Localizable.strings
Binary file not shown.
Binary file modified seafile/cs.lproj/Localizable.strings
Binary file not shown.
Binary file modified seafile/de.lproj/Localizable.strings
Binary file not shown.
Binary file modified seafile/es.lproj/Localizable.strings
Binary file not shown.
Binary file modified seafile/fr.lproj/Localizable.strings
Binary file not shown.
Binary file modified seafile/hu.lproj/Localizable.strings
Binary file not shown.
Binary file modified seafile/is.lproj/Localizable.strings
Binary file not shown.
Binary file modified seafile/it.lproj/Localizable.strings
Binary file not shown.
Binary file modified seafile/ja.lproj/Localizable.strings
Binary file not shown.
Binary file modified seafile/ko.lproj/Localizable.strings
Binary file not shown.
Binary file modified seafile/nb.lproj/Localizable.strings
Binary file not shown.
Binary file modified seafile/pl.lproj/Localizable.strings
Binary file not shown.
Binary file modified seafile/pt-BR.lproj/Localizable.strings
Binary file not shown.
Binary file modified seafile/pt-PT.lproj/Localizable.strings
Binary file not shown.
Binary file modified seafile/ru.lproj/Localizable.strings
Binary file not shown.
2 changes: 1 addition & 1 deletion seafile/seafile-appstore-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<string>2</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
Expand Down
Binary file modified seafile/tr.lproj/Localizable.strings
Binary file not shown.
Binary file modified seafile/zh-Hans.lproj/Localizable.strings
Binary file not shown.
6 changes: 6 additions & 0 deletions seafilePro.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1903,6 +1903,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: xie zheng (V5PK24Q5Y5)";
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
EMBEDDED_CONTENT_CONTAINS_SWIFT = NO;
ENABLE_BITCODE = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "seafile/seafile-Prefix.pch";
HEADER_SEARCH_PATHS = "$(inherited)";
Expand Down Expand Up @@ -1932,6 +1933,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution";
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
EMBEDDED_CONTENT_CONTAINS_SWIFT = NO;
ENABLE_BITCODE = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "seafile/seafile-Prefix.pch";
HEADER_SEARCH_PATHS = "$(inherited)";
Expand Down Expand Up @@ -1964,6 +1966,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
EMBEDDED_CONTENT_CONTAINS_SWIFT = NO;
ENABLE_BITCODE = YES;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
Expand Down Expand Up @@ -1998,6 +2001,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution: Seafile Inc. (55LCTZ5354)";
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
EMBEDDED_CONTENT_CONTAINS_SWIFT = NO;
ENABLE_BITCODE = YES;
ENABLE_NS_ASSERTIONS = NO;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
Expand Down Expand Up @@ -2029,6 +2033,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
EMBEDDED_CONTENT_CONTAINS_SWIFT = NO;
ENABLE_BITCODE = YES;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
Expand Down Expand Up @@ -2065,6 +2070,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution: Seafile Inc. (55LCTZ5354)";
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
EMBEDDED_CONTENT_CONTAINS_SWIFT = NO;
ENABLE_BITCODE = YES;
ENABLE_NS_ASSERTIONS = NO;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
Expand Down

0 comments on commit 5301363

Please sign in to comment.