mirror of
https://github.com/leanote/leanote-android.git
synced 2025-10-14 22:25:40 +00:00
Add VIRTUAL TABLE FTS_NOTE update rule
This commit is contained in:
@@ -63,6 +63,7 @@ public class NoteSyncService extends Service {
|
|||||||
if (!subscriber.isUnsubscribed()) {
|
if (!subscriber.isUnsubscribed()) {
|
||||||
NoteService.fetchFromServer();
|
NoteService.fetchFromServer();
|
||||||
NoteService.pushToServer();
|
NoteService.pushToServer();
|
||||||
|
NoteService.buildFTSNote();
|
||||||
subscriber.onNext(null);
|
subscriber.onNext(null);
|
||||||
subscriber.onCompleted();
|
subscriber.onCompleted();
|
||||||
}
|
}
|
||||||
|
@@ -37,6 +37,18 @@ public class NoteDataStore {
|
|||||||
.queryList();
|
.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) {
|
public static List<Note> searchByFullTextSearch(String keyword) {
|
||||||
Set<Long> set = new LinkedHashSet<>();
|
Set<Long> set = new LinkedHashSet<>();
|
||||||
DatabaseWrapper databaseWrapper = FlowManager.getWritableDatabase(AppDataBase.class);
|
DatabaseWrapper databaseWrapper = FlowManager.getWritableDatabase(AppDataBase.class);
|
||||||
|
@@ -24,11 +24,13 @@ import org.houxg.leamonax.model.UpdateRe;
|
|||||||
import org.houxg.leamonax.network.ApiProvider;
|
import org.houxg.leamonax.network.ApiProvider;
|
||||||
import org.houxg.leamonax.utils.CollectionUtils;
|
import org.houxg.leamonax.utils.CollectionUtils;
|
||||||
import org.houxg.leamonax.utils.RetrofitUtils;
|
import org.houxg.leamonax.utils.RetrofitUtils;
|
||||||
|
import org.houxg.leamonax.utils.SharedPreferenceUtils;
|
||||||
import org.houxg.leamonax.utils.StringUtils;
|
import org.houxg.leamonax.utils.StringUtils;
|
||||||
import org.houxg.leamonax.utils.TimeUtils;
|
import org.houxg.leamonax.utils.TimeUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@@ -38,7 +40,6 @@ import okhttp3.MediaType;
|
|||||||
import okhttp3.MultipartBody;
|
import okhttp3.MultipartBody;
|
||||||
import okhttp3.RequestBody;
|
import okhttp3.RequestBody;
|
||||||
import retrofit2.Call;
|
import retrofit2.Call;
|
||||||
import rx.Observable;
|
|
||||||
|
|
||||||
public class NoteService {
|
public class NoteService {
|
||||||
|
|
||||||
@@ -48,6 +49,8 @@ public class NoteService {
|
|||||||
private static final String MULTIPART_FORM_DATA = "multipart/form-data";
|
private static final String MULTIPART_FORM_DATA = "multipart/form-data";
|
||||||
private static final String CONFLICT_SUFFIX = "--conflict";
|
private static final String CONFLICT_SUFFIX = "--conflict";
|
||||||
private static final int MAX_ENTRY = 20;
|
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() {
|
public static void pushToServer() {
|
||||||
List<Note> notes = NoteDataStore.getAllDirtyNotes(Account.getCurrent().getUserId());
|
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() {
|
public static void fetchFromServer() {
|
||||||
//sync notebook
|
//sync notebook
|
||||||
|
@@ -169,6 +169,7 @@ public class NoteEditActivity extends BaseActivity implements EditorFragment.Edi
|
|||||||
@Override
|
@Override
|
||||||
public void call(Wrapper wrapper) {
|
public void call(Wrapper wrapper) {
|
||||||
saveAsDraft(wrapper);
|
saveAsDraft(wrapper);
|
||||||
|
NoteService.addInCreaseBuildKey(wrapper.note.getId());
|
||||||
setResult(RESULT_OK);
|
setResult(RESULT_OK);
|
||||||
NetworkUtils.checkNetwork();
|
NetworkUtils.checkNetwork();
|
||||||
}
|
}
|
||||||
@@ -240,6 +241,7 @@ public class NoteEditActivity extends BaseActivity implements EditorFragment.Edi
|
|||||||
wrapper.note.delete();
|
wrapper.note.delete();
|
||||||
} else {
|
} else {
|
||||||
saveAsDraft(wrapper);
|
saveAsDraft(wrapper);
|
||||||
|
NoteService.addInCreaseBuildKey(wrapper.note.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user