mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-05 20:45:49 +01:00
cache DB info on groups for better performance
This commit is contained in:
parent
48dd3bb72e
commit
fbfeae379d
2 changed files with 44 additions and 30 deletions
|
@ -864,11 +864,19 @@ public class DBUtils {
|
|||
}
|
||||
}
|
||||
|
||||
private static HashMap<String,GameGroupInfo> s_groupsCache = null;
|
||||
|
||||
private static void invalGroupsCache()
|
||||
{
|
||||
s_groupsCache = null;
|
||||
}
|
||||
|
||||
// Return map of string (group name) to info about all games in
|
||||
// that group.
|
||||
public static HashMap<String,GameGroupInfo> getGroups( Context context )
|
||||
{
|
||||
DbgUtils.logf("getGroupInfo called");
|
||||
if ( null == s_groupsCache ) {
|
||||
HashMap<String,GameGroupInfo> result =
|
||||
new HashMap<String,GameGroupInfo>();
|
||||
initDB( context );
|
||||
|
@ -899,10 +907,12 @@ public class DBUtils {
|
|||
db.close();
|
||||
}
|
||||
DbgUtils.logf("getGroups=>size %d", result.size());
|
||||
return result;
|
||||
s_groupsCache = result;
|
||||
}
|
||||
return s_groupsCache;
|
||||
} // getGroups
|
||||
|
||||
public static long[] getGames( Context context, long groupID )
|
||||
public static long[] getGroupGames( Context context, long groupID )
|
||||
{
|
||||
long[] result = null;
|
||||
initDB( context );
|
||||
|
@ -947,6 +957,7 @@ public class DBUtils {
|
|||
values );
|
||||
db.close();
|
||||
}
|
||||
invalGroupsCache();
|
||||
}
|
||||
}
|
||||
return rowid;
|
||||
|
@ -969,6 +980,7 @@ public class DBUtils {
|
|||
|
||||
db.close();
|
||||
}
|
||||
invalGroupsCache();
|
||||
}
|
||||
|
||||
public static void setGroupName( Context context, long groupid,
|
||||
|
@ -977,6 +989,7 @@ public class DBUtils {
|
|||
ContentValues values = new ContentValues();
|
||||
values.put( DBHelper.GROUPNAME, name );
|
||||
updateRow( context, DBHelper.TABLE_NAME_GROUPS, groupid, values );
|
||||
invalGroupsCache();
|
||||
}
|
||||
|
||||
public static void setGroupExpanded( Context context, long groupid,
|
||||
|
@ -985,6 +998,7 @@ public class DBUtils {
|
|||
ContentValues values = new ContentValues();
|
||||
values.put( DBHelper.EXPANDED, expanded? 1 : 0 );
|
||||
updateRow( context, DBHelper.TABLE_NAME_GROUPS, groupid, values );
|
||||
invalGroupsCache();
|
||||
}
|
||||
|
||||
// Change group id of a game
|
||||
|
|
|
@ -527,7 +527,7 @@ public class GameListAdapter implements ExpandableListAdapter {
|
|||
{
|
||||
GameGroupInfo ggi = gameInfo().get(group);
|
||||
long groupID = ggi.m_id;
|
||||
long[] rows = DBUtils.getGames( m_context, groupID );
|
||||
long[] rows = DBUtils.getGroupGames( m_context, groupID );
|
||||
return rows;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue