Add VIRTUAL TABLE FTS_NOTE update rule

This commit is contained in:
xingxing
2018-06-04 00:09:27 +08:00
parent 35d297a557
commit 9ed4bba184
4 changed files with 44 additions and 1 deletions

View File

@@ -63,6 +63,7 @@ public class NoteSyncService extends Service {
if (!subscriber.isUnsubscribed()) {
NoteService.fetchFromServer();
NoteService.pushToServer();
NoteService.buildFTSNote();
subscriber.onNext(null);
subscriber.onCompleted();
}

View File

@@ -37,6 +37,18 @@ public class NoteDataStore {
.queryList();
}
public static void updateFTSNoteByLocalId(Long localId) {
// DatabaseWrapper databaseWrapper = FlowManager.getWritableDatabase(AppDataBase.class);
// String query = "INSERT INTO fts_note(fts_note) VALUES('rebuild')";//This can be slow
// databaseWrapper.execSQL(query);
}
public static void FTSNoteRebuild() {
DatabaseWrapper databaseWrapper = FlowManager.getWritableDatabase(AppDataBase.class);
String query = "INSERT INTO fts_note(fts_note) VALUES('rebuild')";//This can be slow
databaseWrapper.execSQL(query);
}
public static List<Note> searchByFullTextSearch(String keyword) {
Set<Long> set = new LinkedHashSet<>();
DatabaseWrapper databaseWrapper = FlowManager.getWritableDatabase(AppDataBase.class);

View File

@@ -24,11 +24,13 @@ import org.houxg.leamonax.model.UpdateRe;
import org.houxg.leamonax.network.ApiProvider;
import org.houxg.leamonax.utils.CollectionUtils;
import org.houxg.leamonax.utils.RetrofitUtils;
import org.houxg.leamonax.utils.SharedPreferenceUtils;
import org.houxg.leamonax.utils.StringUtils;
import org.houxg.leamonax.utils.TimeUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
@@ -38,7 +40,6 @@ import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import retrofit2.Call;
import rx.Observable;
public class NoteService {
@@ -48,6 +49,8 @@ public class NoteService {
private static final String MULTIPART_FORM_DATA = "multipart/form-data";
private static final String CONFLICT_SUFFIX = "--conflict";
private static final int MAX_ENTRY = 20;
public static final String SP_HAS_FTS_FULL_BUILD = "sp_has_fts_full_build";
public static final String SP_FTS_INCREASE_BUILD_KES = "sp_has_increase_build_KEYS";
public static void pushToServer() {
List<Note> notes = NoteDataStore.getAllDirtyNotes(Account.getCurrent().getUserId());
@@ -57,6 +60,31 @@ public class NoteService {
}
}
}
public static void buildFTSNote() {
if (!SharedPreferenceUtils.read(SharedPreferenceUtils.CONFIG, SP_HAS_FTS_FULL_BUILD, false)) {
NoteDataStore.FTSNoteRebuild();
SharedPreferenceUtils.write(SharedPreferenceUtils.CONFIG, SP_HAS_FTS_FULL_BUILD, true);
SharedPreferenceUtils.write(SharedPreferenceUtils.CONFIG, SP_FTS_INCREASE_BUILD_KES, "");
} else {
String noteLocalIds = SharedPreferenceUtils.read(SharedPreferenceUtils.CONFIG, SP_FTS_INCREASE_BUILD_KES, "");
String array[] = TextUtils.split(noteLocalIds, ",");
for (String localIdStr: array) {
Long localId = Long.valueOf(localIdStr);
NoteDataStore.updateFTSNoteByLocalId(localId);
}
SharedPreferenceUtils.write(SharedPreferenceUtils.CONFIG, SP_FTS_INCREASE_BUILD_KES, "");
}
}
public static void addInCreaseBuildKey(Long localId) {
String noteLocalIds = SharedPreferenceUtils.read(SharedPreferenceUtils.CONFIG, SP_FTS_INCREASE_BUILD_KES, "");
String array[] = TextUtils.split(noteLocalIds, ",");
List<String> list = new ArrayList<>(Arrays.asList(array));
if (!list.contains(String.valueOf(localId))) {
list.add(String.valueOf(localId));
}
SharedPreferenceUtils.write(SharedPreferenceUtils.CONFIG, SP_FTS_INCREASE_BUILD_KES, TextUtils.join(",", list));
}
public static void fetchFromServer() {
//sync notebook

View File

@@ -169,6 +169,7 @@ public class NoteEditActivity extends BaseActivity implements EditorFragment.Edi
@Override
public void call(Wrapper wrapper) {
saveAsDraft(wrapper);
NoteService.addInCreaseBuildKey(wrapper.note.getId());
setResult(RESULT_OK);
NetworkUtils.checkNetwork();
}
@@ -240,6 +241,7 @@ public class NoteEditActivity extends BaseActivity implements EditorFragment.Edi
wrapper.note.delete();
} else {
saveAsDraft(wrapper);
NoteService.addInCreaseBuildKey(wrapper.note.getId());
}
}
});