Speed up the retrieval of search suggestions from the database.

Since the maximum amount of displayed suggestions is set at 5, it makes
sense to limit the query to a maximum of 5. This speeds up the query
significantly which makes queries more responsive.
This commit is contained in:
Anthony Restaino 2015-01-05 21:20:25 -05:00
parent e8897d43bf
commit 73b367053c

View File

@ -115,7 +115,7 @@ public class HistoryDatabaseHandler extends SQLiteOpenHelper {
List<HistoryItem> itemList = new ArrayList<HistoryItem>();
// select query
String selectQuery = "SELECT * FROM " + TABLE_HISTORY + " WHERE " + KEY_TITLE + " LIKE '%"
+ search + "%' OR " + KEY_URL + " LIKE '%" + search + "%'";
+ search + "%' OR " + KEY_URL + " LIKE '%" + search + "%' LIMIT 5";
Cursor cursor = mDatabase.rawQuery(selectQuery, null);
// looping through all rows and adding to list
@ -139,7 +139,7 @@ public class HistoryDatabaseHandler extends SQLiteOpenHelper {
public List<HistoryItem> getLastHundredItems() {
List<HistoryItem> itemList = new ArrayList<HistoryItem>();
String selectQuery = "SELECT * FROM " + TABLE_HISTORY;
String selectQuery = "SELECT * FROM " + TABLE_HISTORY;
Cursor cursor = mDatabase.rawQuery(selectQuery, null);
int counter = 0;