From 0a33be45a58344b3727906cf3ac17815781e29e3 Mon Sep 17 00:00:00 2001 From: Georg Lukas Date: Sat, 28 May 2011 15:23:31 +0200 Subject: [PATCH] optimize map query --- src/MapAct.scala | 13 ++++++------- src/StorageDatabase.scala | 9 ++++++++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/MapAct.scala b/src/MapAct.scala index 84e00ca..399fe0a 100644 --- a/src/MapAct.scala +++ b/src/MapAct.scala @@ -256,20 +256,19 @@ class StationOverlay(icons : Drawable, context : MapAct, db : StorageDatabase) e c.moveToFirst() var m = new ArrayBuffer[GeoPoint]() while (!c.isAfterLast()) { - val call = c.getString(StorageDatabase.Position.COLUMN_CALL) - val lat = c.getInt(StorageDatabase.Position.COLUMN_LAT) - val lon = c.getInt(StorageDatabase.Position.COLUMN_LON) - val symbol = c.getString(StorageDatabase.Position.COLUMN_SYMBOL) - val comment = c.getString(StorageDatabase.Position.COLUMN_COMMENT) + val call = c.getString(StorageDatabase.Position.COLUMN_MAP_CALL) + val lat = c.getInt(StorageDatabase.Position.COLUMN_MAP_LAT) + val lon = c.getInt(StorageDatabase.Position.COLUMN_MAP_LON) + val symbol = c.getString(StorageDatabase.Position.COLUMN_MAP_SYMBOL) val p = new GeoPoint(lat, lon) m.add(p) // peek at the next row c.moveToNext() - val next_call = if (!c.isAfterLast()) c.getString(StorageDatabase.Position.COLUMN_CALL) else null + val next_call = if (!c.isAfterLast()) c.getString(StorageDatabase.Position.COLUMN_MAP_CALL) else null c.moveToPrevious() if (next_call != call) { //Log.d(TAG, "end of call: " + call + " " + next_call + " " + m.size()) - s.add(new Station(m, p, call, comment, symbol)) + s.add(new Station(m, p, call, null, symbol)) m = new ArrayBuffer[GeoPoint]() } c.moveToNext() diff --git a/src/StorageDatabase.scala b/src/StorageDatabase.scala index 9f43733..2fa141f 100644 --- a/src/StorageDatabase.scala +++ b/src/StorageDatabase.scala @@ -74,6 +74,13 @@ object StorageDatabase { val COLUMN_ALT = 9 val COLUMN_ORIGIN = 10 val COLUMN_QRG = 11 + + lazy val COLUMNS_MAP = Array(_ID, CALL, LAT, LON, SYMBOL) + val COLUMN_MAP_CALL = 1 + val COLUMN_MAP_LAT = 2 + val COLUMN_MAP_LON = 3 + val COLUMN_MAP_SYMBOL = 4 + lazy val TABLE_INDEX = "CREATE INDEX idx_position_%s ON position (%s)" } @@ -188,7 +195,7 @@ class StorageDatabase(context : Context) extends } def getPositions(sel : String, selArgs : Array[String], limit : String) : Cursor = Benchmark("getPositions") { - getReadableDatabase().query(Position.TABLE, Position.COLUMNS, + getReadableDatabase().query(Position.TABLE, Position.COLUMNS_MAP, sel, selArgs, null, null, "CALL, _ID", limit) }