mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 17:46:37 +03:00
Prevent that repeated requests to FileDownloader/FileUploader/SyncFolderHandler get to the worker thread
This commit is contained in:
parent
4f7d416b81
commit
d1a06c2dd3
5 changed files with 50 additions and 37 deletions
|
@ -174,10 +174,11 @@ public class FileDownloader extends Service
|
|||
Pair<String, String> putResult = mPendingDownloads.putIfAbsent(
|
||||
account, file.getRemotePath(), newDownload
|
||||
);
|
||||
if (putResult != null) {
|
||||
String downloadKey = putResult.first;
|
||||
requestedDownloads.add(downloadKey);
|
||||
|
||||
sendBroadcastNewDownload(newDownload, putResult.second);
|
||||
} // else, file already in the queue of downloads; don't repeat the request
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log_OC.e(TAG, "Not enough information provided in intent: " + e.getMessage());
|
||||
|
|
|
@ -300,8 +300,10 @@ public class FileUploader extends Service
|
|||
Pair<String, String> putResult = mPendingUploads.putIfAbsent(
|
||||
account, files[i].getRemotePath(), newUpload
|
||||
);
|
||||
if (putResult != null) {
|
||||
uploadKey = putResult.first;
|
||||
requestedUploads.add(uploadKey);
|
||||
} // else, file already in the queue of uploads; don't repeat the request
|
||||
}
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
|
|
@ -101,11 +101,16 @@ public class IndexedForest<V> {
|
|||
public /* synchronized */ Pair<String, String> putIfAbsent(Account account, String remotePath, V value) {
|
||||
String targetKey = buildKey(account, remotePath);
|
||||
Node<V> valuedNode = new Node(targetKey, value);
|
||||
mMap.putIfAbsent(
|
||||
Node<V> previousValue = mMap.putIfAbsent(
|
||||
targetKey,
|
||||
valuedNode
|
||||
);
|
||||
if (previousValue != null) {
|
||||
// remotePath already known; not replaced
|
||||
return null;
|
||||
|
||||
} else {
|
||||
// value really added
|
||||
String currentPath = remotePath, parentPath = null, parentKey = null;
|
||||
Node<V> currentNode = valuedNode, parentNode = null;
|
||||
boolean linked = false;
|
||||
|
@ -132,7 +137,9 @@ public class IndexedForest<V> {
|
|||
if (linked) {
|
||||
linkedTo = parentNode.getKey().substring(account.name.length());
|
||||
}
|
||||
|
||||
return new Pair<String, String>(targetKey, linkedTo);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -138,9 +138,12 @@ class SyncFolderHandler extends Handler {
|
|||
|
||||
public void add(Account account, String remotePath,
|
||||
SynchronizeFolderOperation syncFolderOperation){
|
||||
Pair<String, String> putResult =
|
||||
mPendingOperations.putIfAbsent(account, remotePath, syncFolderOperation);
|
||||
if (putResult != null) {
|
||||
sendBroadcastNewSyncFolder(account, remotePath); // TODO upgrade!
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -1047,7 +1047,7 @@ public class FileDisplayActivity extends HookActivity
|
|||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
try {
|
||||
String uploadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
|
||||
String uploadedRemotePath = intent.getStringExtra(FileUploader.EXTRA_REMOTE_PATH);
|
||||
String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME);
|
||||
boolean sameAccount = getAccount() != null && accountName.equals(getAccount().name);
|
||||
OCFile currentDir = getCurrentDir();
|
||||
|
@ -1056,7 +1056,7 @@ public class FileDisplayActivity extends HookActivity
|
|||
|
||||
if (sameAccount && isDescendant) {
|
||||
String linkedToRemotePath =
|
||||
intent.getStringExtra(FileDownloader.EXTRA_LINKED_TO_PATH);
|
||||
intent.getStringExtra(FileUploader.EXTRA_LINKED_TO_PATH);
|
||||
if (linkedToRemotePath == null || isAscendant(linkedToRemotePath)) {
|
||||
refreshListOfFilesFragment();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue