add indexes to board table

refactor-toolbar
Floens 7 years ago
parent 7ef0243922
commit 03ad9a5cb9
  1. 9
      Clover/app/src/main/java/org/floens/chan/core/database/DatabaseBoardManager.java
  2. 16
      Clover/app/src/main/java/org/floens/chan/core/database/DatabaseHelper.java
  3. 7
      Clover/app/src/main/java/org/floens/chan/core/model/orm/Board.java
  4. 3
      Clover/app/src/main/java/org/floens/chan/core/repository/BoardRepository.java
  5. 6
      docs/database.txt

@ -179,6 +179,9 @@ public class DatabaseBoardManager {
ordering.put(siteModel.id, siteModel.order); ordering.put(siteModel.id, siteModel.order);
} }
Time.endTiming("getboards sites", start);
start = Time.startTiming();
List<Site> sitesOrdered = new ArrayList<>(sites); List<Site> sitesOrdered = new ArrayList<>(sites);
// Sort the given sites array with these orders. // Sort the given sites array with these orders.
Collections.sort(sitesOrdered, Collections.sort(sitesOrdered,
@ -193,6 +196,9 @@ public class DatabaseBoardManager {
.where().in("site", siteIds) .where().in("site", siteIds)
.query(); .query();
Time.endTiming("getboards boards", start);
start = Time.startTiming();
// Map the boards from siteId to a list of boards. // Map the boards from siteId to a list of boards.
Map<Integer, Site> sitesById = new HashMap<>(); Map<Integer, Site> sitesById = new HashMap<>();
for (Site site : sites) { for (Site site : sites) {
@ -219,7 +225,8 @@ public class DatabaseBoardManager {
res.add(new Pair<>(site, siteBoards)); res.add(new Pair<>(site, siteBoards));
} }
Time.endTiming("getBoardsForAllSitesOrdered", start); Time.endTiming("getboards process", start);
start = Time.startTiming();
return res; return res;
}; };

@ -45,7 +45,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
private static final String TAG = "DatabaseHelper"; private static final String TAG = "DatabaseHelper";
private static final String DATABASE_NAME = "ChanDB"; private static final String DATABASE_NAME = "ChanDB";
private static final int DATABASE_VERSION = 24; private static final int DATABASE_VERSION = 25;
public Dao<Pin, Integer> pinDao; public Dao<Pin, Integer> pinDao;
public Dao<Loadable, Integer> loadableDao; public Dao<Loadable, Integer> loadableDao;
@ -235,7 +235,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
try { try {
pinDao.executeRawNoArgs("ALTER TABLE board ADD COLUMN \"archive\" INTEGER;"); pinDao.executeRawNoArgs("ALTER TABLE board ADD COLUMN \"archive\" INTEGER;");
} catch (SQLException e) { } catch (SQLException e) {
Logger.e(TAG, "Error upgrading to version 14", e); Logger.e(TAG, "Error upgrading to version 23", e);
} }
} }
@ -243,7 +243,17 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
try { try {
siteDao.executeRawNoArgs("ALTER TABLE site ADD COLUMN \"order\" INTEGER;"); siteDao.executeRawNoArgs("ALTER TABLE site ADD COLUMN \"order\" INTEGER;");
} catch (SQLException e) { } catch (SQLException e) {
Logger.e(TAG, "Error upgrading to version 14", e); Logger.e(TAG, "Error upgrading to version 24", e);
}
}
if (oldVersion < 25) {
try {
boardsDao.executeRawNoArgs("CREATE INDEX board_site_idx ON board(site);");
boardsDao.executeRawNoArgs("CREATE INDEX board_saved_idx ON board(saved);");
boardsDao.executeRawNoArgs("CREATE INDEX board_value_idx ON board(value);");
} catch (SQLException e) {
Logger.e(TAG, "Error upgrading to version 25", e);
} }
} }
} }

@ -34,7 +34,7 @@ public class Board implements SiteReference {
@DatabaseField(generatedId = true) @DatabaseField(generatedId = true)
public int id; public int id;
@DatabaseField(columnName = "site") @DatabaseField(columnName = "site", index = true, indexName = "board_site_idx")
public int siteId; public int siteId;
/** /**
@ -45,7 +45,7 @@ public class Board implements SiteReference {
/** /**
* The board appears in the dropdown. * The board appears in the dropdown.
*/ */
@DatabaseField @DatabaseField(index = true, indexName = "board_saved_idx")
public boolean saved = false; public boolean saved = false;
/** /**
@ -57,7 +57,8 @@ public class Board implements SiteReference {
@DatabaseField(columnName = "key") // named key for legacy support @DatabaseField(columnName = "key") // named key for legacy support
public String name; public String name;
@DatabaseField(columnName = "value") // named value for legacy support // named value for legacy support
@DatabaseField(columnName = "value", index = true, indexName = "board_value_idx")
// TODO(sec) force filter this to ascii & numbers. // TODO(sec) force filter this to ascii & numbers.
public String code; public String code;

@ -52,11 +52,12 @@ public class BoardRepository implements Observer {
this.siteRepository = siteRepository; this.siteRepository = siteRepository;
allSites = this.siteRepository.all(); allSites = this.siteRepository.all();
allSites.addObserver(this);
} }
public void initialize() { public void initialize() {
updateObservablesSync(); updateObservablesSync();
allSites.addObserver(this);
} }
@Override @Override

@ -80,3 +80,9 @@ ALTER TABLE board ADD COLUMN "archive" INTEGER;
Changes in version 24: Changes in version 24:
ALTER TABLE site ADD COLUMN "order" INTEGER; ALTER TABLE site ADD COLUMN "order" INTEGER;
Changes in version 25:
CREATE INDEX board_site_idx ON board(site);
CREATE INDEX board_saved_idx ON board(saved);
CREATE INDEX board_value_idx ON board(value);

Loading…
Cancel
Save