Compare commits

...
26 Commits
Author SHA1 Message Date
Joris Bodin 61fe75e981 Merge branch 'master' into optimization 2020-01-15 12:58:18 +01:00
Joris Bodin 2a01aca904 Merge branch 'master' into optimization 2020-01-10 15:18:00 +01:00
Joris Bodin 87855c1335 Oups
Signed-off-by: Joris Bodin <[email protected]>
2020-01-10 15:02:45 +01:00
Joris Bodin 0f54b71716 Merge branch 'master' into optimization 2020-01-10 11:41:16 +01:00
Joris Bodin 4ce14abb2c Fix bug on first connect
Signed-off-by: Joris Bodin <[email protected]>
2020-01-10 11:39:47 +01:00
Joris Bodin bff8068f2b Merge branch 'master' into optimization 2020-01-08 10:23:45 +01:00
Joris Bodin 0960d08321 Fix when search file
Signed-off-by: Joris Bodin <[email protected]>
2020-01-07 18:35:40 +01:00
Joris Bodin b17373cddf Merge branch 'master' into optimization 2020-01-07 11:17:15 +01:00
Joris Bodin 0d6114283d Export createContentValue for saveFile()
Signed-off-by: Joris Bodin <[email protected]>
2020-01-06 19:04:14 +01:00
Joris Bodin d7122e70e4 Remove createContentValueForFile doublon
Signed-off-by: Joris Bodin <[email protected]>
2020-01-06 18:44:46 +01:00
Joris Bodin f47fa94046 Add old comment
Signed-off-by: Joris Bodin <[email protected]>
2020-01-06 18:05:52 +01:00
Joris Bodin f303cd0dab Prepare remove duplication
Signed-off-by: Joris Bodin <[email protected]>
2020-01-06 17:16:05 +01:00
Joris Bodin 56f8b3befc Merge remote-tracking branch 'origin/master' into optimization 2020-01-06 15:46:03 +01:00
Joris Bodin 65acb834ef Finish extract deleteFiles and applyBatch
Signed-off-by: Joris Bodin <[email protected]>
2020-01-06 15:45:32 +01:00
Joris Bodin f7c8bf2f4c Extract insertFile and DeleteFiles
Signed-off-by: Joris Bodin <[email protected]>
2020-01-06 14:33:29 +01:00
Joris Bodin 2b69892694 Extract method for applyBatch and updateFiles
Signed-off-by: Joris Bodin <[email protected]>
2020-01-06 14:13:57 +01:00
Joris Bodin af606603de Merge remote-tracking branch 'origin/master' into optimization 2020-01-06 11:54:52 +01:00
Joris Bodin f22b386cc5 Finish refactor FileDataStorageManager
Rename file to ocFile for OCFile object to avoid ambiguity with the objects of type File
Remove unUsed variable != null (i check method caller)
Add != null is necessary
Rename to camelCase
Consistency in the code

Signed-off-by: Joris Bodin <[email protected]>
2020-01-03 12:57:56 +01:00
Joris Bodin 724147d272 Begin refactor FileDataStorageManager
And readd localFile = mStorageManager.getFileByPath(updatedFile.getRemotePath());
And optimize insert virtualFile

Signed-off-by: Joris Bodin <[email protected]>
2020-01-02 18:52:55 +01:00
Joris Bodin 235ca28bc6 Optimization RemoveSharesInFolder
Signed-off-by: Joris Bodin <[email protected]>
2020-01-02 10:34:15 +01:00
Joris Bodin 1c19846711 Remove bulkInsert and optimize applyBatch (only >= Android M)
Before avg 6s (for avg new 1000 files) now 0.2s with applyBatch

Signed-off-by: Joris Bodin <[email protected]>
2019-12-27 12:07:05 +01:00
Joris Bodin 87a8ab5f07 Split query for SQL variables limit and remove unused method
Signed-off-by: Joris Bodin <[email protected]>
2019-12-27 10:52:33 +01:00
Joris Bodin 339770fa92 bulkInsert is more efficient
avg 15s to 0.2s for 900 new files !
Remove unnecessary double check and very old method not used (since 2015)

Signed-off-by: Joris Bodin <[email protected]>
2019-12-26 17:48:29 +01:00
Joris Bodin 068ff229a7 Fix sql injection
Signed-off-by: Joris Bodin <[email protected]>
2019-12-26 10:29:49 +01:00
Joris Bodin aa11e9b1ee Optimization isFileExists
Signed-off-by: Joris Bodin <[email protected]>
2019-12-24 16:44:04 +01:00
Joris Bodin 2ff6d73470 Refactor fileExists
Signed-off-by: Joris Bodin <[email protected]>
2019-12-24 11:20:40 +01:00
5 changed files with 1129 additions and 1504 deletions

No files matched your search

File diff suppressed because it is too large. Load diff
@@ -412,7 +412,7 @@ public class RefreshFolderOperation extends RemoteOperation {
Log_OC.d(TAG, "Remote folder " + mLocalFolder.getRemotePath() + " changed - starting update of local data ");
List<OCFile> updatedFiles = new ArrayList<>(folderAndFiles.size() - 1);
ArrayList<OCFile> updatedFiles = new ArrayList<>(folderAndFiles.size() - 1);
mFilesToSyncContents.clear();
// if local folder is encrypted, download fresh metadata
@@ -435,20 +435,21 @@ public class RefreshFolderOperation extends RemoteOperation {
OCFile remoteFile;
OCFile localFile;
OCFile updatedFile;
RemoteFile r;
RemoteFile remote;
for (int i = 1; i < folderAndFiles.size(); i++) {
/// new OCFile instance with the data from the server
r = (RemoteFile) folderAndFiles.get(i);
remoteFile = FileStorageUtils.fillOCFile(r);
remote = (RemoteFile) folderAndFiles.get(i);
remoteFile = FileStorageUtils.fillOCFile(remote);
// new OCFile instance to merge fresh data from server with local state
updatedFile = FileStorageUtils.fillOCFile(r);
updatedFile = FileStorageUtils.fillOCFile(remote);
updatedFile.setParentId(mLocalFolder.getFileId());
// retrieve local data for the read file
localFile = localFilesMap.remove(remoteFile.getRemotePath());
// TODO better implementation is needed
if (localFile == null) {
localFile = mStorageManager.getFileByPath(updatedFile.getRemotePath());
}
@@ -43,6 +43,7 @@ import com.owncloud.android.utils.FileStorageUtils;
import com.owncloud.android.utils.MimeTypeUtil;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -262,7 +263,7 @@ public class SynchronizeFolderOperation extends SyncOperation {
}
FileDataStorageManager storageManager = getStorageManager();
List<OCFile> updatedFiles = new Vector<>(folderAndFiles.size() - 1);
ArrayList<OCFile> updatedFiles = new ArrayList<>(folderAndFiles.size() - 1);
// get current data about local contents of the folder to synchronize
List<OCFile> localFiles = storageManager.getFolderContent(mLocalFolder, false);
@@ -40,6 +40,7 @@ import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import android.os.Binder;
import android.os.Build;
import android.text.TextUtils;
import com.nextcloud.client.core.Clock;
@@ -265,28 +266,21 @@ public class FileContentProvider extends ContentProvider {
switch (mUriMatcher.match(uri)) {
case ROOT_DIRECTORY:
case SINGLE_FILE:
String remotePath = values.getAsString(ProviderTableMeta.FILE_PATH);
String accountName = values.getAsString(ProviderTableMeta.FILE_ACCOUNT_OWNER);
String[] projection = new String[]{
ProviderTableMeta._ID, ProviderTableMeta.FILE_PATH,
ProviderTableMeta.FILE_ACCOUNT_OWNER
};
String where = ProviderTableMeta.FILE_PATH + "=? AND " + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
String[] whereArgs = new String[]{remotePath, accountName};
String remotePath = values.getAsString(ProviderTableMeta.FILE_PATH);
String accountName = values.getAsString(ProviderTableMeta.FILE_ACCOUNT_OWNER);
String[] whereArgs = {remotePath, accountName};
Cursor doubleCheck = query(db, uri, projection, where, whereArgs, null);
// TODO better implementation is needed
// ugly patch; serious refactorization is needed to reduce work in
// FileDataStorageManager and bring it to FileContentProvider
if (doubleCheck == null || !doubleCheck.moveToFirst()) {
if (doubleCheck != null) {
doubleCheck.close();
}
long rowId = db.insert(ProviderTableMeta.FILE_TABLE_NAME, null, values);
if (rowId > 0) {
return ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, rowId);
} else {
throw new SQLException(ERROR + uri);
}
} else {
if (doubleCheck.moveToFirst()) {
// file is already inserted; race condition, let's avoid a duplicated entry
Uri insertedFileUri = ContentUris.withAppendedId(
ProviderTableMeta.CONTENT_URI_FILE,
@@ -295,13 +289,22 @@ public class FileContentProvider extends ContentProvider {
doubleCheck.close();
return insertedFileUri;
} else {
doubleCheck.close();
long rowId = db.insert(ProviderTableMeta.FILE_TABLE_NAME, null, values);
if (rowId > 0) {
return ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, rowId);
} else {
throw new SQLException(ERROR + uri);
}
}
case SHARES:
Uri insertedShareUri;
long rowId = db.insert(ProviderTableMeta.OCSHARES_TABLE_NAME, null, values);
if (rowId > 0) {
insertedShareUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_SHARE, rowId);
long idShares = db.insert(ProviderTableMeta.OCSHARES_TABLE_NAME, null, values);
if (idShares > 0) {
insertedShareUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_SHARE, idShares);
} else {
throw new SQLException(ERROR + uri);
@@ -312,9 +315,9 @@ public class FileContentProvider extends ContentProvider {
case CAPABILITIES:
Uri insertedCapUri;
long id = db.insert(ProviderTableMeta.CAPABILITIES_TABLE_NAME, null, values);
if (id > 0) {
insertedCapUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_CAPABILITIES, id);
long idCapabilities = db.insert(ProviderTableMeta.CAPABILITIES_TABLE_NAME, null, values);
if (idCapabilities > 0) {
insertedCapUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_CAPABILITIES, idCapabilities);
} else {
throw new SQLException(ERROR + uri);
}
@@ -653,6 +656,30 @@ public class FileContentProvider extends ContentProvider {
}
}
@Override
public int bulkInsert(@NonNull Uri uri, @NonNull ContentValues[] values) {
if (isCallerNotAllowed(uri)) {
return 0;
}
if (mUriMatcher.match(uri) == VIRTUAL) {
SQLiteDatabase database = mDbHelper.getWritableDatabase();
database.beginTransaction();
int contentInsert;
try {
for (ContentValues contentValues : values) {
insert(database, uri, contentValues);
}
database.setTransactionSuccessful();
contentInsert = values.length;
} finally {
database.endTransaction();
}
return contentInsert;
}
return super.bulkInsert(uri, values);
}
@NonNull
@Override
public ContentProviderResult[] applyBatch(@NonNull ArrayList<ContentProviderOperation> operations)
@@ -662,16 +689,22 @@ public class FileContentProvider extends ContentProvider {
ContentProviderResult[] results = new ContentProviderResult[operations.size()];
int i = 0;
SQLiteDatabase db = mDbHelper.getWritableDatabase();
db.beginTransaction(); // it's supposed that transactions can be nested
SQLiteDatabase database = mDbHelper.getWritableDatabase();
database.beginTransaction(); // it's supposed that transactions can be nested
try {
for (ContentProviderOperation operation : operations) {
results[i] = operation.apply(this, results, i);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && operation.isInsert()) {
ContentValues contentValues = operation.resolveValueBackReferences(results, i);
Uri newUri = insert(database, operation.getUri(), contentValues);
results[i] = new ContentProviderResult(newUri);
} else {
results[i] = operation.apply(this, results, i);
}
i++;
}
db.setTransactionSuccessful();
database.setTransactionSuccessful();
} finally {
db.endTransaction();
database.endTransaction();
}
Log_OC.d("FileContentProvider", "applied batch in provider " + this);
return results;
@@ -896,6 +896,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
}
}
}
mStorageManager.saveShares(shares);
}
@@ -968,7 +969,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
}
preferences.setPhotoSearchTimestamp(System.currentTimeMillis());
mStorageManager.saveVirtuals(type, contentValues);
mStorageManager.saveVirtuals(contentValues);
}
public void showVirtuals(VirtualFolderType type, boolean onlyImages, FileDataStorageManager storageManager) {