Skip to content
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

make updating fts search tables optional #926

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,12 @@ By placing a file named `app.properties` in your implementation assets folder (S
### Configurable Settings

| Configuration | Type | Default | Description |
| ---------------------------------------- | ------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| ---------------------------------------- | ------- | ------- |-----------------------------------------------------------------------------------------------------------------------------------------------------|
| `system.toaster.centered` | Boolean | false | Position toaster(s) at the center of the view(s) |
| `disable.location.picker.view` | Boolean | false | Disables LocationPicker View |
| `location.picker.tag.shown` | Boolean | false | Hides/Shows the location tag in the location picker tree view |
| `encrypt.shared.preferences` | Boolean | false | Enable/disables encrypting SharedPreferences |
| `allow.offline.login.with.invalid.token` | Boolean | false | Allow offline login when token is no longer valid after a successful login when online and user is forcefully logged out |
| `enable.search.button` | Boolean | false | Enable/Disable search to be triggered only after clicking the search icon in `org.smartregister.view.fragment.BaseRegisterFragment` or its subclass |
| `feature.profile.images.disabled` | Boolean | false | Disable profile image capturing and rendering |
| `feature.profile.images.disabled` | Boolean | false | Disable profile image capturing and rendering |
| `disable.fts.search` | Boolean | false | Disable fts search which can slow down sync process |
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=6.1.4-SNAPSHOT
VERSION_NAME=6.1.5-ALPHA48-SNAPSHOT
VERSION_CODE=1
GROUP=org.smartregister
POM_SETTING_DESCRIPTION=OpenSRP Client Core Application
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ org.gradle.daemon=true
org.gradle.parallel=true
zipStoreBase=GRADLE_USER_HOME
org.gradle.configureondemand=true
org.gradle.jvmargs=-Xmx2048m
org.gradle.jvmargs=-Xmx2048m --add-opens java.base/java.io=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ public static class PROPERTY {
public static final String IGNORE_LOCATION_DELETION = "ignore.location.deletion";
public static final String ENABLE_SEARCH_BUTTON = "enable.search.button";
public static final String DISABLE_PROFILE_IMAGES_FEATURE = "feature.profile.images.disabled";
public static final String DISABLE_FTS_SEARCH_DISABLE="disable.fts.search";
}

public static class HTTP_REQUEST_HEADERS {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.database.Cursor;

import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteStatement;

import org.smartregister.commonregistry.CommonPersonObject;
import org.smartregister.commonregistry.CommonPersonObjectClient;
Expand Down Expand Up @@ -33,8 +34,10 @@
}

public void add(String baseEntityId, String key, String value, Long timestamp) {
SQLiteDatabase database = masterRepository().getWritableDatabase();
SQLiteDatabase database = masterRepository().getReadableDatabase();
// long start = System.currentTimeMillis();
Boolean exists = getIdForDetailsIfExists(baseEntityId, key, value);
// Timber.d("check if details exist's took %s, ", System.currentTimeMillis() - start);
if (exists == null) { // Value has not changed, no need to update
return;
}
Expand All @@ -45,17 +48,94 @@
values.put(VALUE_COLUMN, value);
values.put(EVENT_DATE_COLUMN, timestamp);

if (exists) {
int updated = database.update(TABLE_NAME, values,
BASE_ENTITY_ID_COLUMN + " = ? AND " + KEY_COLUMN + " MATCH ? ",
new String[]{baseEntityId, key});
//Log.i(getClass().getName(), "Detail Row Updated: " + String.valueOf(updated));
} else {
long rowId = database.insert(TABLE_NAME, null, values);
if (exists) {
long startUpdate = System.currentTimeMillis();

Check warning on line 52 in opensrp-core/src/main/java/org/smartregister/repository/DetailsRepository.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

opensrp-core/src/main/java/org/smartregister/repository/DetailsRepository.java#L52

Avoid unused local variables such as 'startUpdate'.
int updated = database.update(TABLE_NAME, values,
BASE_ENTITY_ID_COLUMN + " = ? AND " + KEY_COLUMN + " MATCH ? ",
new String[]{baseEntityId, key});
// Timber.d("updating details for %S took %s, ", TABLE_NAME, System.currentTimeMillis() - startUpdate);
//Log.i(getClass().getName(), "Detail Row Updated: " + String.valueOf(updated));
} else {
long insertStart = System.currentTimeMillis();

Check warning on line 59 in opensrp-core/src/main/java/org/smartregister/repository/DetailsRepository.java

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

opensrp-core/src/main/java/org/smartregister/repository/DetailsRepository.java#L59

Avoid unused local variables such as 'insertStart'.
long rowId = database.insert(TABLE_NAME, null, values);
// Timber.d("insert into details %s table took %s, ", TABLE_NAME, System.currentTimeMillis() - insertStart);
//Log.i(getClass().getName(), "Details Row Inserted : " + String.valueOf(rowId));
}
}

public void batchInsertDetails(Map<String, String> values, long timestamp) {
SQLiteDatabase database = null;
SQLiteStatement insertStatement = null;
SQLiteStatement updateStatement = null;

try {
database = masterRepository().getWritableDatabase();
// Start transaction
database.beginTransaction();

// Prepare the SQL for inserts and updates
String insertSQL = "INSERT INTO " + TABLE_NAME + " (" +
BASE_ENTITY_ID_COLUMN + ", " + KEY_COLUMN + ", " + VALUE_COLUMN + ", " + EVENT_DATE_COLUMN +
") VALUES (?, ?, ?, ?)";

String updateSQL = "UPDATE " + TABLE_NAME + " SET " + VALUE_COLUMN + " = ?, " +
EVENT_DATE_COLUMN + " = ? WHERE " + BASE_ENTITY_ID_COLUMN + " = ? AND " + KEY_COLUMN + " = ?";

insertStatement = database.compileStatement(insertSQL);
updateStatement = database.compileStatement(updateSQL);

String baseEntityId = values.get(BASE_ENTITY_ID_COLUMN);


for (String key : values.keySet()) {
String val = values.get(key);
if(val == null ) continue;
Boolean exists = getIdForDetailsIfExists(baseEntityId, key, val);

if (exists == null) { // Value has not changed, no need to update
continue;
}

if (exists) {
// Bind values for update
updateStatement.bindString(1, val); // Bind VALUE_COLUMN
updateStatement.bindLong(2, timestamp); // Bind EVENT_DATE_COLUMN
updateStatement.bindString(3, baseEntityId); // Bind BASE_ENTITY_ID_COLUMN
updateStatement.bindString(4, key); // Bind KEY_COLUMN

// Execute the update
updateStatement.execute();
updateStatement.clearBindings();
} else {
// Bind values for insert
insertStatement.bindString(1, baseEntityId); // Bind BASE_ENTITY_ID_COLUMN
insertStatement.bindString(2, key); // Bind KEY_COLUMN
insertStatement.bindString(3, val); // Bind VALUE_COLUMN
insertStatement.bindLong(4, timestamp); // Bind EVENT_DATE_COLUMN

// Execute the insert
insertStatement.executeInsert();
insertStatement.clearBindings();
}
}
database.setTransactionSuccessful();
} catch (Exception e) {
Timber.e(e);
} finally {
// End the transaction
if (database != null) {
database.endTransaction();
}
// Close the prepared statements
if (insertStatement != null) {
insertStatement.close();
}
if (updateStatement != null) {
updateStatement.close();
}
}
}

private Boolean getIdForDetailsIfExists(String baseEntityId, String key, String value) {
Cursor mCursor = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,6 @@ public LoginResponse urlCanBeAccessWithGivenCredentials(String requestURL, Strin
if (inputStream != null)
responseString = IOUtils.toString(inputStream);
if (statusCode == HttpURLConnection.HTTP_OK) {

Timber.d("response String: %s using request url %s", responseString, url);
LoginResponseData responseData = getResponseBody(responseString);
loginResponse = retrieveResponse(responseData);
} else if (statusCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
Expand Down Expand Up @@ -355,8 +353,6 @@ private Response<String> processResponse(HttpURLConnection urlConnection) {

totalRecords = urlConnection.getHeaderField(AllConstants.SyncProgressConstants.TOTAL_RECORDS);

Timber.d("response string: %s using url %s", responseString, urlConnection.getURL());

} catch (MalformedURLException exception) {
Timber.e(exception, "%s %s", MALFORMED_URL, exception.toString());
ResponseStatus.failure.setDisplayValue(ResponseErrorStatus.malformed_url.name());
Expand Down
Loading
Loading