Search index performance improvements.

This commit is contained in:
Brian Pellin
2009-12-27 23:38:32 -06:00
parent 9087a10ebf
commit bfde297588
2 changed files with 22 additions and 2 deletions

View File

@@ -37,6 +37,7 @@ import org.phoneid.keepassj2me.PwManager;
import org.phoneid.keepassj2me.Types;
import android.content.Context;
import android.os.Debug;
import com.keepassdroid.keepasslib.InvalidKeyFileException;
import com.keepassdroid.keepasslib.InvalidPasswordException;
@@ -110,20 +111,23 @@ public class Database {
*/
public void buildSearchIndex(Context ctx) {
Debug.startMethodTracing("search");
searchHelper = new SearchDbHelper(ctx);
initSearch();
searchHelper.open();
for ( int i = 0; i < mPM.entries.size(); i++) {
searchHelper.insertEntry(mPM.entries);
/*for ( int i = 0; i < mPM.entries.size(); i++) {
PwEntry entry = mPM.entries.get(i);
if ( ! entry.isMetaStream() ) {
searchHelper.insertEntry(entry);
}
}
} */
searchHelper.close();
indexBuilt = true;
Debug.stopMethodTracing();
}
public PwGroup Search(String str) {

View File

@@ -53,6 +53,8 @@ public class SearchDbHelper {
+ KEY_URL + ", "
+ KEY_COMMENT + ");";
private static final String PRAGMA_NO_SYNCHRONOUS = "pragma synchronous = off;";
private final Context mCtx;
private DatabaseHelper mDbHelper;
private SQLiteDatabase mDb;
@@ -82,6 +84,7 @@ public class SearchDbHelper {
public SearchDbHelper open() throws SQLException {
mDbHelper = new DatabaseHelper(mCtx);
mDb = mDbHelper.getWritableDatabase();
mDb.execSQL(PRAGMA_NO_SYNCHRONOUS);
return this;
}
@@ -112,6 +115,19 @@ public class SearchDbHelper {
mDb.insert(SEARCH_TABLE, null, cv);
}
public void insertEntry(Vector<PwEntry> entries) {
mDb.beginTransaction();
try {
for (int i=0; i < entries.size(); i++) {
insertEntry(entries.get(i));
}
mDb.setTransactionSuccessful();
} finally {
mDb.endTransaction();
}
}
public void updateEntry(PwEntry entry) {
ContentValues cv = buildNewEntryContent(entry);
String uuidStr = cv.getAsString(KEY_UUID);