Skip to content

Commit

Permalink
Merge pull request #1 from Flipkart/master
Browse files Browse the repository at this point in the history
Sync with origin master
  • Loading branch information
ankit-w committed Jun 11, 2019
2 parents 5e39e07 + bab2433 commit 4649452
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 120 deletions.
1 change: 1 addition & 0 deletions android/android.iml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
<excludeFolder url="file://$MODULE_DIR$/build" />
</content>
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
Expand Down
2 changes: 1 addition & 1 deletion android/dus/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dependencies {
testCompile 'org.robolectric:robolectric:3.3.2'
testCompile 'org.mockito:mockito-core:2.18.0'
compile 'com.vimeo.stag:stag-library:2.5.1'
compile 'com.facebook.react:react-native:0.47.+'
compile 'com.facebook.react:react-native:+'
annotationProcessor 'com.vimeo.stag:stag-library-compiler:2.5.1'
}

Expand Down
9 changes: 2 additions & 7 deletions android/dus/dus.iml
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,18 @@
<orderEntry type="library" exported="" scope="TEST" name="junit:junit:4.12@jar" level="project" />
<orderEntry type="library" exported="" name="com.android.support:animated-vector-drawable-23.2.1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="org.ow2.asm:asm-tree:5.0.1@jar" level="project" />
<orderEntry type="library" exported="" name="javax.inject:javax.inject:1@jar" level="project" />
<orderEntry type="library" exported="" name="com.android.support:appcompat-v7-23.2.1" level="project" />
<orderEntry type="library" exported="" name="com.facebook.fresco:imagepipeline-base-1.3.0" level="project" />
<orderEntry type="library" exported="" name="com.parse.bolts:bolts-tasks:1.4.0@jar" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="org.ow2.asm:asm-commons:5.0.1@jar" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="org.apache.ant:ant:1.8.0@jar" level="project" />
<orderEntry type="library" exported="" name="com.google.code.findbugs:jsr305:3.0.0@jar" level="project" />
<orderEntry type="library" exported="" name="com.squareup.okhttp3:okhttp-urlconnection:3.6.0@jar" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="org.ow2.asm:asm-commons:5.0.1@jar" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="org.apache.ant:ant:1.8.0@jar" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="org.robolectric:shadows-core:3.0@jar" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="org.apache.ant:ant-launcher:1.8.0@jar" level="project" />
<orderEntry type="library" exported="" name="com.facebook.soloader:soloader-0.1.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="com.ximpleware:vtd-xml:2.11@jar" level="project" />
<orderEntry type="library" exported="" name="com.squareup.okio:okio:1.13.0@jar" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="org.ow2.asm:asm-analysis:5.0.1@jar" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="org.robolectric:robolectric-annotations:3.0@jar" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="org.objenesis:objenesis:2.1@jar" level="project" />
Expand All @@ -135,16 +134,12 @@
<orderEntry type="library" exported="" name="com.vimeo.stag:stag-library:2.1.2@jar" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="com.almworks.sqlite4java:sqlite4java:0.282@jar" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="org.ow2.asm:asm:5.0.1@jar" level="project" />
<orderEntry type="library" exported="" name="com.squareup.okhttp3:okhttp:3.6.0@jar" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="org.robolectric:robolectric-utils:3.0@jar" level="project" />
<orderEntry type="library" exported="" name="com.facebook.fresco:fbcore-1.3.0" level="project" />
<orderEntry type="library" exported="" name="com.facebook.fresco:drawee-1.3.0" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="com.ibm.icu:icu4j:53.1@jar" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="org.apache.maven:maven-ant-tasks:2.1.3@jar" level="project" />
<orderEntry type="library" exported="" name="com.facebook.fbui.textlayoutbuilder:staticlayout-proxy:1.0@jar" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="org.robolectric:robolectric-resources:3.0@jar" level="project" />
<orderEntry type="library" exported="" name="com.facebook.fbui.textlayoutbuilder:textlayoutbuilder-1.0.0" level="project" />
<orderEntry type="library" exported="" name="com.android.support:support-annotations:25.3.1@jar" level="project" />
<orderEntry type="library" exported="" name="org.webkit:android-jsc-r174650" level="project" />
</component>
</module>
40 changes: 29 additions & 11 deletions android/dus/src/main/java/com/flipkart/dus/DUSContentProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.database.Cursor;
import android.database.MatrixCursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
Expand Down Expand Up @@ -136,10 +137,10 @@ public Cursor query(@NonNull Uri uri, String[] projection, String selection, Str
} else {
String filePath = getFileHelper().getFilePath(getScreenMaker().getFileKey(screenType));
if (TextUtils.isEmpty(filePath)) {
shouldRefresh = getScreenMaker().fetchPage(screenType, getContext());
screenInfo = new ScreenInfo();
screenInfo.status = DUSContracts.LOADING;
mCachedScreenInfo.put(screenType, screenInfo);
shouldRefresh = getScreenMaker().fetchPage(screenType, getContext());
cursor = generateResponse(DUSContracts.LOADING, "");
} else {
screenInfo = new ScreenInfo();
Expand Down Expand Up @@ -255,22 +256,32 @@ public int delete(@NonNull Uri uri, String selection, @Nullable String[] selecti
getLoggerInstance().log("[SYNC] [DELETE]" + uri.toString());
switch (sUriMatcher.match(uri)) {
case DUSContracts.JS_COMPONENTS:
getDatabaseHelper().getWritableDatabase().execSQL("DELETE FROM " + TABLE_COMPONENTS + selection);
try {
getDatabaseHelper().getWritableDatabase().execSQL("DELETE FROM " + TABLE_COMPONENTS + selection);
} catch (SQLiteException e) {
//Do nothing. This is a rare case and the database file
//should get deleted when the db is opened the next time
}
break;
case DUSContracts.JS_BUNDLE:
if (selectionArgs != null) {
//Removing screentypes of those pages for which we are refreshing the bundles
for (String screenType :
selectionArgs) {
mCachedScreenInfo.remove(screenType);
}
//Removing bundle files for all pages. We try to keep
//all the bundle files which belong to the list of the files that needs to be deleted
//but already have a bundle formed with the latest update graph version
ArrayList<String> filesToKeep = new ArrayList<>(selectionArgs.length);
for (String screenType : selectionArgs) {
filesToKeep.add(getScreenMaker().getFileKey(screenType));
filesToKeep.add(screenType);
}
getFileHelper().deleteRestOfFiles(filesToKeep);
}
break;
case DUSContracts.CLEAR:
mCachedScreenInfo.clear();
getDatabaseHelper().getWritableDatabase().delete(TABLE_COMPONENTS, null, null);
getFileHelper().deleteAllFiles();
}
Expand All @@ -292,16 +303,21 @@ public int bulkInsert(@NonNull Uri uri, @NonNull ContentValues[] values) {
getLoggerInstance().log("[SYNC] [BULK_INSERT] " + uri.toString());
switch (sUriMatcher.match(uri)) {
case DUSContracts.JS_COMPONENTS: {
SQLiteDatabase database = getDatabaseHelper().getWritableDatabase();
database.beginTransaction();
try {
for (ContentValues contentValue :
values) {
database.insertWithOnConflict(TABLE_COMPONENTS, null, contentValue, SQLiteDatabase.CONFLICT_REPLACE);
SQLiteDatabase database = getDatabaseHelper().getWritableDatabase();
database.beginTransaction();
try {
for (ContentValues contentValue :
values) {
database.insertWithOnConflict(TABLE_COMPONENTS, null, contentValue, SQLiteDatabase.CONFLICT_REPLACE);
}
database.setTransactionSuccessful();
} finally {
database.endTransaction();
}
database.setTransactionSuccessful();
} finally {
database.endTransaction();
} catch (SQLiteException e) {
//Do nothing. This is a rare case and the database file
//should get deleted when the db is opened the next time
}
}
}
Expand Down Expand Up @@ -361,7 +377,9 @@ public void attachInfo(Context context, @NonNull ProviderInfo info) {
Log.d(TAG, "Getting authority: " + DUSContracts.CONTENT_AUTHORITY);
sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
sUriMatcher.addURI(DUSContracts.CONTENT_AUTHORITY, DUSContracts.PATH_JS_BUNDLE + "/*", DUSContracts.JS_BUNDLE);
sUriMatcher.addURI(DUSContracts.CONTENT_AUTHORITY, DUSContracts.PATH_JS_BUNDLE, DUSContracts.JS_BUNDLE);
sUriMatcher.addURI(DUSContracts.CONTENT_AUTHORITY, DUSContracts.PATH_JS_COMPONENTS + "/*", DUSContracts.JS_COMPONENTS);
sUriMatcher.addURI(DUSContracts.CONTENT_AUTHORITY, DUSContracts.PATH_JS_COMPONENTS, DUSContracts.JS_COMPONENTS);
sUriMatcher.addURI(DUSContracts.CONTENT_AUTHORITY, DUSContracts.PATH_UPDATEGRAPH, DUSContracts.UPDATE_GRAPH);
sUriMatcher.addURI(DUSContracts.CONTENT_AUTHORITY, DUSContracts.PATH_CLEAR, DUSContracts.CLEAR);
super.attachInfo(context, info);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void addToDownloadQueue(@NonNull final DownloadJob downloadJob) {
mNetworkInterface.getResponseString(new ArrayList<>(downloadList), new ResponseInterface<HashMap<String, String>>() {
@Override
public void OnSuccess(@NonNull HashMap<String, String> networkResponse) {
if (networkResponse.size() != downloadJob.getComponentKeys().size()) {
if (networkResponse.size() != downloadList.size()) {
ErrorResponse errorResponse = new ErrorResponse();
errorResponse.setErrorResponse("Could not fetch all files");
clearCallbackMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabaseCorruptException;
import android.os.AsyncTask;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.util.ArrayMap;
Expand Down Expand Up @@ -62,7 +65,12 @@ public boolean fetchPage(@NonNull final String screenType, @NonNull final Contex
screenTypeBeingProcessed.remove(screenType);
}
} else {
fetchComponents(screenType, context, componentsKeys);
AsyncTask.THREAD_POOL_EXECUTOR.execute(new Runnable() {
@Override
public void run() {
fetchComponents(screenType, context, componentsKeys);
}
});
}
}
return refreshGraph;
Expand All @@ -72,19 +80,23 @@ public boolean fetchPage(@NonNull final String screenType, @NonNull final Contex
private void fetchComponents(@NonNull final String screenName, @NonNull final Context context, @NonNull final ArrayList<String> componentsKeys) {
ArrayList<String> keysToDownload = new ArrayList<>(componentsKeys.size());
keysToDownload.addAll(componentsKeys);
Cursor cachedComponents = context.getContentResolver().query(DUSContracts.buildFetchContentsUri(screenName), null, DUSContracts.getComponentsQuery(componentsKeys), null, null);
final ArrayMap<String, String> componentMap = new ArrayMap<>(componentsKeys.size());
if (cachedComponents != null) {
if (cachedComponents.getCount() > 0) {
cachedComponents.moveToFirst();
do {
String key = cachedComponents.getString(cachedComponents.getColumnIndex(DatabaseHelper.COMPONENT_KEY));
String value = cachedComponents.getString(cachedComponents.getColumnIndex(DatabaseHelper.COMPONENT_VALUE));
componentMap.put(key, value);
keysToDownload.remove(key);
} while (cachedComponents.moveToNext());
try {
Cursor cachedComponents = context.getContentResolver().query(DUSContracts.buildFetchContentsUri(screenName), null, DUSContracts.getComponentsQuery(componentsKeys), null, null);
if (cachedComponents != null) {
if (cachedComponents.getCount() > 0) {
cachedComponents.moveToFirst();
do {
String key = cachedComponents.getString(cachedComponents.getColumnIndex(DatabaseHelper.COMPONENT_KEY));
String value = cachedComponents.getString(cachedComponents.getColumnIndex(DatabaseHelper.COMPONENT_VALUE));
componentMap.put(key, value);
keysToDownload.remove(key);
} while (cachedComponents.moveToNext());
}
cachedComponents.close();
}
cachedComponents.close();
} catch (SQLException e) {
//DO nothing as the chunks would get downloaded.
}

if (keysToDownload.size() == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,15 @@ private void optimizeCache(@NonNull FileConfig fileConfig, @NonNull Context cont
fileConfig.getCurrentUpdateGraph().entrySet()) {
componentList.addAll(screenList.getValue());
}
String[] fileList = new String[fileConfig.getCurrentUpdateGraph().size()];
context.getContentResolver().delete(DUSContracts.buildFetchContentsUri(""), DUSContracts.getOptimizeStorageWhereQuery(componentList), null);
int i = 0;
for (String file : fileConfig.getCurrentUpdateGraph().keySet()) {
fileList[i] = generateFileKey(file);
i++;
}
context.getContentResolver().delete(DUSContracts.buildFetchPageUri(""), null, fileList);
mFileConfigHelper.setShouldOptimize(false);
}

@Nullable
Expand Down
Loading

0 comments on commit 4649452

Please sign in to comment.