mirror of
https://github.com/nextcloud/android.git
synced 2024-11-23 13:45:35 +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
|
||||
);
|
||||
String downloadKey = putResult.first;
|
||||
requestedDownloads.add(downloadKey);
|
||||
|
||||
sendBroadcastNewDownload(newDownload, putResult.second);
|
||||
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
|
||||
);
|
||||
uploadKey = putResult.first;
|
||||
requestedUploads.add(uploadKey);
|
||||
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,38 +101,45 @@ 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(
|
||||
targetKey,
|
||||
valuedNode
|
||||
Node<V> previousValue = mMap.putIfAbsent(
|
||||
targetKey,
|
||||
valuedNode
|
||||
);
|
||||
if (previousValue != null) {
|
||||
// remotePath already known; not replaced
|
||||
return null;
|
||||
|
||||
String currentPath = remotePath, parentPath = null, parentKey = null;
|
||||
Node<V> currentNode = valuedNode, parentNode = null;
|
||||
boolean linked = false;
|
||||
while (!OCFile.ROOT_PATH.equals(currentPath) && !linked) {
|
||||
parentPath = new File(currentPath).getParent();
|
||||
if (!parentPath.endsWith(OCFile.PATH_SEPARATOR)) {
|
||||
parentPath += OCFile.PATH_SEPARATOR;
|
||||
} else {
|
||||
// value really added
|
||||
String currentPath = remotePath, parentPath = null, parentKey = null;
|
||||
Node<V> currentNode = valuedNode, parentNode = null;
|
||||
boolean linked = false;
|
||||
while (!OCFile.ROOT_PATH.equals(currentPath) && !linked) {
|
||||
parentPath = new File(currentPath).getParent();
|
||||
if (!parentPath.endsWith(OCFile.PATH_SEPARATOR)) {
|
||||
parentPath += OCFile.PATH_SEPARATOR;
|
||||
}
|
||||
parentKey = buildKey(account, parentPath);
|
||||
parentNode = mMap.get(parentKey);
|
||||
if (parentNode == null) {
|
||||
parentNode = new Node(parentKey, null);
|
||||
parentNode.addChild(currentNode);
|
||||
mMap.put(parentKey, parentNode);
|
||||
} else {
|
||||
parentNode.addChild(currentNode);
|
||||
linked = true;
|
||||
}
|
||||
currentPath = parentPath;
|
||||
currentNode = parentNode;
|
||||
}
|
||||
parentKey = buildKey(account, parentPath);
|
||||
parentNode = mMap.get(parentKey);
|
||||
if (parentNode == null) {
|
||||
parentNode = new Node(parentKey, null);
|
||||
parentNode.addChild(currentNode);
|
||||
mMap.put(parentKey, parentNode);
|
||||
} else {
|
||||
parentNode.addChild(currentNode);
|
||||
linked = true;
|
||||
}
|
||||
currentPath = parentPath;
|
||||
currentNode = parentNode;
|
||||
}
|
||||
|
||||
String linkedTo = OCFile.ROOT_PATH;
|
||||
if (linked) {
|
||||
linkedTo = parentNode.getKey().substring(account.name.length());
|
||||
String linkedTo = OCFile.ROOT_PATH;
|
||||
if (linked) {
|
||||
linkedTo = parentNode.getKey().substring(account.name.length());
|
||||
}
|
||||
|
||||
return new Pair<String, String>(targetKey, linkedTo);
|
||||
}
|
||||
return new Pair<String, String>(targetKey, linkedTo);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -138,8 +138,11 @@ class SyncFolderHandler extends Handler {
|
|||
|
||||
public void add(Account account, String remotePath,
|
||||
SynchronizeFolderOperation syncFolderOperation){
|
||||
mPendingOperations.putIfAbsent(account, remotePath, syncFolderOperation);
|
||||
sendBroadcastNewSyncFolder(account, remotePath); // TODO upgrade!
|
||||
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