-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimization after split up #5337
base: master
Are you sure you want to change the base?
Conversation
@@ -100,6 +100,114 @@ public FileDataStorageManager(Account account, ContentProviderClient contentProv | |||
this.account = account; | |||
} | |||
|
|||
private Cursor executeQuery(Uri uri, String[] projection, String selection, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have the code style convention that if a line with parameters needs to be wrapped, that we then put all parameters in a separate line, so
private Cursor executeQuery(Uri uri,
String[] projection,
String selection,
String[] selectionArgs,
String sortOrder,
String errorMessage)
{
I will change it, but just for your info :-) (it is not that bad, if we sometimes forget this, but it makes diff a bit easier, if a paremeter gets changed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,
I take note for next time :)
c7998aa
to
008f1af
Compare
e9f1c79
to
37bf0dd
Compare
3c44331
to
e05c649
Compare
Issues
======
+ Solved 5
- Added 18
Complexity decreasing per file
==============================
+ src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java -3
See the complete overview on Codacy |
return contentProviderResults; | ||
} | ||
|
||
private ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} catch (RemoteException e) { | ||
Log_OC.e(TAG, "Could not get file details: " + e.getMessage(), e); | ||
cursor = null; | ||
private ArrayList<OCFile> getFilesExistsID(ArrayList<OCFile> updatedFiles) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return executeQuery(uri, null, selection, selectionArgs, null, errorMessage); | ||
} | ||
|
||
private ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations, String errorMessage) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
listIDString.clear(); | ||
listPathString.clear(); | ||
StringBuilder inList = new StringBuilder(loopSize * 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue found: Avoid instantiating new objects inside loops
if (cursor != null) { | ||
if (cursor.moveToFirst()) { | ||
do { | ||
OCFile ocFile = new OCFile(cursor.getString(cursor.getColumnIndex(ProviderTableMeta.FILE_PATH))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue found: Avoid instantiating new objects inside loops
+ ProviderTableMeta.FILE_PATH | ||
+ " IN (" + inList + "))"; | ||
|
||
ArrayList<String> selectionArgsList = new ArrayList<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue found: Avoid instantiating new objects inside loops
selectionArgsList.add(account.name); | ||
selectionArgsList.addAll(listIDString); | ||
selectionArgsList.addAll(listPathString); | ||
String[] selectionArgs = selectionArgsList.toArray(new String[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue found: Avoid instantiating new objects inside loops
Log_OC.e(TAG, "Failed querying for descendents in conflict " + e.getMessage(), e); | ||
} | ||
} | ||
selectionArgs = new String[]{account.name, parentPath + "%"}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue found: Avoid instantiating new objects inside loops
for (int i = 0; i < loopSize; i++, processSize++) { | ||
OCFile ocFile = updatedFiles.get(processSize); | ||
if (i > 0) { | ||
inList.append(","); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
processSize = 0; | ||
|
||
do { | ||
loopSize = Math.min((totalSize - processSize), 499); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue found: Useless parentheses.
src/main/java/com/owncloud/android/datamodel/FileDataStorageManager.java
Outdated
Show resolved
Hide resolved
return deleted; | ||
} | ||
|
||
private int deleteFiles(Uri uri, String where, String[] whereArgs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -357,19 +451,24 @@ public void saveNewFile(OCFile newFile) { | |||
* @param updatedFiles | |||
* @param filesToRemove | |||
*/ | |||
public void saveFolder(OCFile folder, List<OCFile> updatedFiles, Collection<OCFile> filesToRemove) { | |||
public void saveFolder(OCFile folder, ArrayList<OCFile> updatedFiles, Collection<OCFile> filesToRemove) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (i > 0) { | ||
inList.append(","); | ||
} | ||
inList.append("?"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
processSize = 0; | ||
|
||
do { | ||
loopSize = Math.min((totalSize - processSize), 998); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue found: Useless parentheses.
loopSize = Math.min((totalSize - processSize), 998); | ||
|
||
listPathString.clear(); | ||
StringBuilder inList = new StringBuilder(folderContent.size() * 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue found: Avoid instantiating new objects inside loops
saveFile(newFile); | ||
} else { | ||
throw new IllegalArgumentException("Saving a new file in an unexisting folder"); | ||
private boolean isFileExists(ArrayList<OCFile> filesExists, OCFile ocFile) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ArrayList<String> listIDString = new ArrayList<>(); | ||
ArrayList<String> listPathString = new ArrayList<>(); | ||
|
||
int totalSize, processSize, loopSize; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
APK file: https://www.kaminsky.me/nc-dev/android-artifacts/14490.apk |
Optimization isFileExists Fix sql injection bulkInsert is more efficient Split query for SQL variables limit and remove unused method Remove bulkInsert and optimize applyBatch (only >= Android M) Optimization RemoveSharesInFolder Begin refactor FileDataStorageManager Finish refactor FileDataStorageManager Extract method for applyBatch and updateFiles Extract insertFile and DeleteFiles Finish extract deleteFiles and applyBatch Prepare remove duplication Add old comment Remove createContentValueForFile doublon Export createContentValue for saveFile() Fix when search file Fix bug on first connect Oups Signed-off-by: Joris Bodin <[email protected]> Signed-off-by: tobiasKaminsky <[email protected]>
Signed-off-by: tobiasKaminsky <[email protected]>
e05c649
to
a5196d5
Compare
Signed-off-by: tobiasKaminsky <[email protected]>
APK file: https://www.kaminsky.me/nc-dev/android-artifacts/5337.apk |
master-IT test failed: https://www.kaminsky.me/nc-dev/android-integrationTests/4954-IT-master-17-20 |
stable-IT test failed: https://www.kaminsky.me/nc-dev/android-integrationTests/4954-IT-stable-17-25 |
This is second PR after splitup of #5150
It includes only code optimizations, done by @JorisBodin
Plan is to have all possible/needed tests in #5336 and then they need to work also on this PR before merging.
For checking that everything was split up correctly, you can compare this PR with #5150
Signed-off-by: tobiasKaminsky [email protected]