Skip to content

Commit

Permalink
Better solution for #411 based on feedback from @nbradbury. Limit the…
Browse files Browse the repository at this point in the history
… number of ‘list’ type stats fragments to the STATS_GROUP_MAX_ITEMS constant value at the sql level.
  • Loading branch information
roundhill committed Dec 9, 2013
1 parent 878f721 commit 7040129
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 18 deletions.
5 changes: 3 additions & 2 deletions src/org/wordpress/android/datasets/StatsClickGroupsTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.net.Uri;

import org.wordpress.android.models.StatsClickGroup;
import org.wordpress.android.ui.stats.StatsActivity;
import org.wordpress.android.ui.stats.StatsTimeframe;

/**
Expand Down Expand Up @@ -87,12 +88,12 @@ public static ContentValues getContentValues(StatsClickGroup item) {
@Override
public Cursor query(SQLiteDatabase database, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {

String sort = NAME + "." + Columns.TOTAL + " DESC, " + NAME + "." + Columns.NAME + " ASC";
String sort = NAME + "." + Columns.TOTAL + " DESC, " + NAME + "." + Columns.NAME + " ASC LIMIT " + StatsActivity.STATS_GROUP_MAX_ITEMS;

String timeframe = uri.getQueryParameter("timeframe");
if (timeframe == null)
return super.query(database, uri, projection, selection, selectionArgs, sort);

// get the latest for "Today", and the next latest for "Yesterday"
if (timeframe.equals(StatsTimeframe.TODAY.name())) {
return database.rawQuery("SELECT * FROM " + NAME +", " +
Expand Down
3 changes: 2 additions & 1 deletion src/org/wordpress/android/datasets/StatsGeoviewsTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.net.Uri;

import org.wordpress.android.models.StatsGeoview;
import org.wordpress.android.ui.stats.StatsActivity;
import org.wordpress.android.ui.stats.StatsTimeframe;

/**
Expand Down Expand Up @@ -77,7 +78,7 @@ public static ContentValues getContentValues(StatsGeoview item) {
@Override
public Cursor query(SQLiteDatabase database, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {

String sort = NAME + "." + Columns.VIEWS + " DESC, " + NAME + "." + Columns.COUNTRY + " ASC";
String sort = NAME + "." + Columns.VIEWS + " DESC, " + NAME + "." + Columns.COUNTRY + " ASC LIMIT " + StatsActivity.STATS_GROUP_MAX_ITEMS;

String timeframe = uri.getQueryParameter("timeframe");
if (timeframe == null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package org.wordpress.android.datasets;

import java.util.LinkedHashMap;
import java.util.Map;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;

import org.wordpress.android.models.StatsReferrerGroup;
import org.wordpress.android.ui.stats.StatsActivity;
import org.wordpress.android.ui.stats.StatsTimeframe;

import java.util.LinkedHashMap;
import java.util.Map;

/**
* A database table to represent groups in the stats for referrers.
* A group may or may not have children.
Expand Down Expand Up @@ -88,7 +89,7 @@ public static ContentValues getContentValues(StatsReferrerGroup item) {
@Override
public Cursor query(SQLiteDatabase database, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {

String sort = NAME + "." + Columns.TOTAL + " DESC, " + NAME + "." + Columns.NAME + " ASC";
String sort = NAME + "." + Columns.TOTAL + " DESC, " + NAME + "." + Columns.NAME + " ASC LIMIT " + StatsActivity.STATS_GROUP_MAX_ITEMS;

String timeframe = uri.getQueryParameter("timeframe");
if (timeframe == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.net.Uri;

import org.wordpress.android.models.StatsSearchEngineTerm;
import org.wordpress.android.ui.stats.StatsActivity;
import org.wordpress.android.ui.stats.StatsTimeframe;

/**
Expand Down Expand Up @@ -73,7 +74,7 @@ public static ContentValues getContentValues(StatsSearchEngineTerm item) {

@Override
public Cursor query(SQLiteDatabase database, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
String sort = NAME + "." + Columns.VIEWS + " DESC, " + NAME + "." + Columns.SEARCH + " ASC";
String sort = NAME + "." + Columns.VIEWS + " DESC, " + NAME + "." + Columns.SEARCH + " ASC LIMIT " + StatsActivity.STATS_GROUP_MAX_ITEMS;

String timeframe = uri.getQueryParameter("timeframe");
if (timeframe == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.net.Uri;

import org.wordpress.android.models.StatsTopPostsAndPages;
import org.wordpress.android.ui.stats.StatsActivity;
import org.wordpress.android.ui.stats.StatsTimeframe;

/**
Expand Down Expand Up @@ -79,7 +80,7 @@ public static ContentValues getContentValues(StatsTopPostsAndPages item) {

@Override
public Cursor query(SQLiteDatabase database, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
String sort = NAME + "." + Columns.VIEWS + " DESC, " + NAME + "." + Columns.TITLE + " ASC";
String sort = NAME + "." + Columns.VIEWS + " DESC, " + NAME + "." + Columns.TITLE + " ASC LIMIT " + StatsActivity.STATS_GROUP_MAX_ITEMS;

String timeframe = uri.getQueryParameter("timeframe");
if (timeframe == null)
Expand Down
3 changes: 3 additions & 0 deletions src/org/wordpress/android/ui/stats/StatsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
*/
public class StatsActivity extends WPActionBarActivity {

// Max number of rows to show in a stats fragment
public static final int STATS_GROUP_MAX_ITEMS = 10;

private static final String SAVED_NAV_POSITION = "SAVED_NAV_POSITION";
private static final String SAVED_WP_LOGIN_STATE = "SAVED_WP_LOGIN_STATE";
private static final int REQUEST_JETPACK = 7000;
Expand Down
5 changes: 1 addition & 4 deletions src/org/wordpress/android/ui/stats/StatsCursorFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.actionbarsherlock.app.SherlockFragment;

import org.wordpress.android.R;
import org.wordpress.android.WordPress;
import org.wordpress.android.util.Utils;

/**
* A fragment that appears as a 'page' in the {@link StatsAbsPagedViewFragment}.
Expand All @@ -41,7 +39,6 @@
*/
public class StatsCursorFragment extends SherlockFragment implements LoaderManager.LoaderCallbacks<Cursor> {

private static final int MAX_ITEMS_ON_TABLET = 10;
private static final String ARGS_URI = "ARGS_URI";
private static final String ARGS_ENTRY_LABEL = "ARGS_ENTRY_LABEL";
private static final String ARGS_TOTALS_LABEL = "ARGS_TOTALS_LABEL";
Expand Down Expand Up @@ -164,7 +161,7 @@ private void reloadLinearLayout() {
mLinearLayout.removeAllViews();

// limit number of items to show otherwise it would cause performance issues on the linearlayout
int count = Math.min(mAdapter.getCount(), MAX_ITEMS_ON_TABLET);
int count = Math.min(mAdapter.getCount(), StatsActivity.STATS_GROUP_MAX_ITEMS);
for (int i = 0; i < count; i++) {
View view = mAdapter.getView(i, null, mLinearLayout);
if (i % 2 == 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@
*/
public class StatsCursorTreeFragment extends SherlockFragment implements LoaderManager.LoaderCallbacks<Cursor>, StatsCursorLoaderCallback {

private static final int MAX_ITEMS = 10;
private static final int LOADER_URI_GROUP_INDEX = -1;

private static final String ARGS_GROUP_URI = "ARGS_GROUP_URI";
private static final String ARGS_CHILDREN_URI = "ARGS_CHILDREN_URI";
private static final String ARGS_ENTRY_LABEL = "ARGS_ENTRY_LABEL";
Expand Down Expand Up @@ -175,8 +173,8 @@ public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
if (loader.getId() == LOADER_URI_GROUP_INDEX) {

// start loaders on children
for (int i = 0; i < Math.min(data.getCount(), MAX_ITEMS); i++) {
data.moveToPosition(i);
while (data.moveToNext()) {
//data.moveToPosition(i);
String groupId = data.getString(data.getColumnIndex("groupId"));
long date = data.getLong(data.getColumnIndex("date"));

Expand Down Expand Up @@ -234,7 +232,7 @@ private void reloadLinearLayout() {
mLinearLayout.removeAllViews();

// limit number of items to show otherwise it would cause performance issues on the linearlayout
int groupCount = Math.min(mAdapter.getGroupCount(), MAX_ITEMS);
int groupCount = Math.min(mAdapter.getGroupCount(), StatsActivity.STATS_GROUP_MAX_ITEMS);
for (int i = 0; i < groupCount; i++) {

boolean isExpanded = mGroupIdToExpandedMap.get(i);
Expand Down

0 comments on commit 7040129

Please sign in to comment.