Merge branch 'master' into circular

# By Samuel Clay (3) and Lance Johnson (1)
# Via Daniel (1) and Samuel Clay (1)
* master:
  Increasing task queue size.
  Fixing pipeline.
  Using pipeline for syncing redis user stories.
  Fix login/logout problem of old activities hanging around on back stack from the previous users' session. More info in issue #142
This commit is contained in:
Samuel Clay 2013-04-08 17:11:50 -07:00
commit 8e4f0f453a
21 changed files with 101 additions and 42 deletions

View file

@ -660,10 +660,12 @@ class MUserStory(mongo.Document):
return story.id
def sync_redis(self, r=None):
if not r:
def sync_redis(self, r=None, pipeline=None):
if pipeline:
r = pipeline
elif not r:
r = redis.Redis(connection_pool=settings.REDIS_STORY_POOL)
if self.story_db_id:
all_read_stories_key = 'RS:%s' % (self.user_id)
r.sadd(all_read_stories_key, self.story_db_id)
@ -704,10 +706,12 @@ class MUserStory(mongo.Document):
total = read_stories.count()
print " ---> Syncing %s stories (%s)" % (total, user_id or feed_id)
pipeline = r.pipeline()
for i, read_story in enumerate(read_stories):
if (i+1) % 1000 == 0:
print " ---> %s/%s" % (i+1, total)
read_story.sync_redis(r)
read_story.sync_redis(r, pipeline=pipeline)
pipeline.execute()
class UserSubscriptionFolders(models.Model):
"""

View file

@ -33,8 +33,8 @@ class TaskFeeds(Task):
r.zcard('scheduled_updates')))
# Regular feeds
if tasked_feeds_size < 1000:
feeds = r.srandmember('queued_feeds', 1000)
if tasked_feeds_size < 2000:
feeds = r.srandmember('queued_feeds', 1500)
Feed.task_feeds(feeds, verbose=True)
active_count = len(feeds)
else:

View file

@ -5,10 +5,9 @@ import android.text.TextUtils;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.newsblur.R;
public class AddFacebook extends SherlockFragmentActivity {
public class AddFacebook extends NbFragmentActivity {
public static final int FACEBOOK_AUTHED = 0x21;
private WebView webview;

View file

@ -8,11 +8,10 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.newsblur.R;
import com.newsblur.fragment.AddFollowFragment;
public class AddFollow extends SherlockFragmentActivity {
public class AddFollow extends NbFragmentActivity {
private FragmentManager fragmentManager;
private String currentTag = "addFollowFragment";

View file

@ -11,12 +11,11 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.newsblur.R;
import com.newsblur.fragment.AddSitesListFragment;
import com.newsblur.network.APIManager;
public class AddSites extends SherlockFragmentActivity {
public class AddSites extends NbFragmentActivity {
private FragmentManager fragmentManager;
private String currentTag = "addsitesFragment";

View file

@ -8,11 +8,10 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.newsblur.R;
import com.newsblur.fragment.AddSocialFragment;
public class AddSocial extends SherlockFragmentActivity {
public class AddSocial extends NbFragmentActivity {
private FragmentManager fragmentManager;
private String currentTag = "addSocialFragment";

View file

@ -5,10 +5,9 @@ import android.text.TextUtils;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.newsblur.R;
public class AddTwitter extends SherlockFragmentActivity {
public class AddTwitter extends NbFragmentActivity {
public static final int TWITTER_AUTHED = 0x20;
private WebView webview;

View file

@ -1,7 +1,6 @@
package com.newsblur.activity;
import com.actionbarsherlock.app.SherlockFragmentActivity;
public class FeedSearch extends SherlockFragmentActivity {
public class FeedSearch extends NbFragmentActivity {
}

View file

@ -5,10 +5,9 @@ import android.text.TextUtils;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.newsblur.R;
public class ImportFeeds extends SherlockFragmentActivity {
public class ImportFeeds extends NbFragmentActivity {
private WebView webContainer;

View file

@ -5,7 +5,6 @@ import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.util.Log;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.view.Window;
@ -15,7 +14,7 @@ import com.newsblur.fragment.ItemListFragment;
import com.newsblur.fragment.SyncUpdateFragment;
import com.newsblur.view.StateToggleButton.StateChangedListener;
public abstract class ItemsList extends SherlockFragmentActivity implements SyncUpdateFragment.SyncUpdateFragmentInterface, StateChangedListener {
public abstract class ItemsList extends NbFragmentActivity implements SyncUpdateFragment.SyncUpdateFragmentInterface, StateChangedListener {
public static final String EXTRA_STATE = "currentIntelligenceState";
public static final String EXTRA_BLURBLOG_USERNAME = "blurblogName";

View file

@ -1,5 +1,6 @@
package com.newsblur.activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
@ -34,7 +35,7 @@ public class Login extends FragmentActivity {
}
private void preferenceCheck() {
final SharedPreferences preferences = getSharedPreferences(PrefConstants.PREFERENCES, 0);
final SharedPreferences preferences = getSharedPreferences(PrefConstants.PREFERENCES, Context.MODE_PRIVATE);
if (preferences.getString(PrefConstants.PREF_COOKIE, null) != null) {
final Intent mainIntent = new Intent(this, Main.class);
startActivity(mainIntent);

View file

@ -7,7 +7,6 @@ import android.support.v4.app.FragmentManager;
import android.util.Log;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
@ -19,7 +18,7 @@ import com.newsblur.fragment.SyncUpdateFragment;
import com.newsblur.service.SyncService;
import com.newsblur.view.StateToggleButton.StateChangedListener;
public class Main extends SherlockFragmentActivity implements StateChangedListener, SyncUpdateFragment.SyncUpdateFragmentInterface {
public class Main extends NbFragmentActivity implements StateChangedListener, SyncUpdateFragment.SyncUpdateFragmentInterface {
private ActionBar actionBar;
private FolderListFragment folderFeedList;

View file

@ -0,0 +1,48 @@
package com.newsblur.activity;
import android.os.Bundle;
import android.util.Log;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.newsblur.util.PrefsUtils;
public class NbFragmentActivity extends SherlockFragmentActivity {
private final static String UNIQUE_LOGIN_KEY = "uniqueLoginKey";
private String uniqueLoginKey;
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
if(bundle == null) {
uniqueLoginKey = PrefsUtils.getUniqueLoginKey(this);
} else {
uniqueLoginKey = bundle.getString(UNIQUE_LOGIN_KEY);
}
finishIfNotLoggedIn();
}
@Override
protected void onResume() {
super.onResume();
finishIfNotLoggedIn();
}
protected void finishIfNotLoggedIn() {
String currentLoginKey = PrefsUtils.getUniqueLoginKey(this);
if(currentLoginKey == null || !currentLoginKey.equals(uniqueLoginKey)) {
Log.d( this.getClass().getName(), "This activity was for a different login. finishing it.");
finish();
}
}
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
savedInstanceState.putString(UNIQUE_LOGIN_KEY, uniqueLoginKey);
super.onSaveInstanceState(savedInstanceState);
}
}

View file

@ -6,7 +6,6 @@ import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.text.TextUtils;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.MenuItem;
import com.newsblur.R;
import com.newsblur.domain.UserDetails;
@ -17,7 +16,7 @@ import com.newsblur.network.domain.ActivitiesResponse;
import com.newsblur.network.domain.ProfileResponse;
import com.newsblur.util.PrefsUtils;
public class Profile extends SherlockFragmentActivity {
public class Profile extends NbFragmentActivity {
private FragmentManager fragmentManager;
private String detailsTag = "details";

View file

@ -10,7 +10,6 @@ import android.content.Intent;
import android.content.OperationApplicationException;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.RemoteException;
import android.support.v4.app.DialogFragment;
@ -21,9 +20,7 @@ import android.text.TextUtils;
import android.util.Log;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.Toast;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
@ -44,7 +41,7 @@ import com.newsblur.util.PrefConstants;
import com.newsblur.util.PrefsUtils;
import com.newsblur.util.UIUtils;
public abstract class Reading extends SherlockFragmentActivity implements OnPageChangeListener, SyncUpdateFragment.SyncUpdateFragmentInterface, OnSeekBarChangeListener {
public abstract class Reading extends NbFragmentActivity implements OnPageChangeListener, SyncUpdateFragment.SyncUpdateFragmentInterface, OnSeekBarChangeListener {
public static final String EXTRA_FEED = "feed_selected";
public static final String TAG = "ReadingActivity";

View file

@ -3,13 +3,11 @@ package com.newsblur.activity;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.newsblur.R;
import com.newsblur.fragment.RegisterProgressFragment;
public class RegisterProgress extends SherlockFragmentActivity {
public class RegisterProgress extends NbFragmentActivity {
private FragmentManager fragmentManager;
private String currentTag = "fragment";

View file

@ -13,7 +13,6 @@ import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
@ -24,7 +23,7 @@ import com.newsblur.fragment.AddFeedFragment;
import com.newsblur.network.SearchAsyncTaskLoader;
import com.newsblur.network.SearchLoaderResponse;
public class SearchForFeeds extends SherlockFragmentActivity implements LoaderCallbacks<SearchLoaderResponse>, OnItemClickListener {
public class SearchForFeeds extends NbFragmentActivity implements LoaderCallbacks<SearchLoaderResponse>, OnItemClickListener {
private static final int LOADER_TWITTER_SEARCH = 0x01;
private ListView resultsList;
private Loader<SearchLoaderResponse> searchLoader;

View file

@ -14,13 +14,12 @@ import android.widget.TextView;
import com.newsblur.R;
import com.newsblur.activity.Login;
import com.newsblur.database.BlurDatabase;
import com.newsblur.network.APIManager;
import com.newsblur.util.PrefConstants;
import com.newsblur.util.PrefsUtils;
public class LogoutDialogFragment extends DialogFragment {
protected static final String TAG = "LogoutDialogFragment";
private APIManager apiManager;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -31,7 +30,6 @@ public class LogoutDialogFragment extends DialogFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
apiManager = new APIManager(getActivity());
View v = inflater.inflate(R.layout.fragment_logout_dialog, container, false);
final TextView message = (TextView) v.findViewById(R.id.dialog_message);
message.setText(getActivity().getResources().getString(R.string.logout_warning));
@ -45,6 +43,7 @@ public class LogoutDialogFragment extends DialogFragment {
BlurDatabase databaseHelper = new BlurDatabase(getActivity().getApplicationContext());
databaseHelper.dropAndRecreateTables();
PrefsUtils.clearLogin(getActivity());
Intent i = new Intent(getActivity(), Login.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);

View file

@ -75,7 +75,7 @@ public class APIManager {
final APIResponse response = client.post(APIConstants.URL_LOGIN, values);
if (response.responseCode == HttpStatus.SC_OK && !response.hasRedirected) {
LoginResponse loginResponse = gson.fromJson(response.responseString, LoginResponse.class);
PrefsUtils.saveCookie(context, response.cookie);
PrefsUtils.saveLogin(context, username, response.cookie);
return loginResponse;
} else {
return new LoginResponse();
@ -185,7 +185,7 @@ public class APIManager {
final APIResponse response = client.post(APIConstants.URL_SIGNUP, values);
if (response.responseCode == HttpStatus.SC_OK && !response.hasRedirected) {
LoginResponse loginResponse = gson.fromJson(response.responseString, LoginResponse.class);
PrefsUtils.saveCookie(context, response.cookie);
PrefsUtils.saveLogin(context, username, response.cookie);
CookieSyncManager.createInstance(context.getApplicationContext());
CookieManager cookieManager = CookieManager.getInstance();

View file

@ -4,6 +4,7 @@ public class PrefConstants {
public static final String PREFERENCES = "preferences";
public static final String PREF_COOKIE = "login_cookie";
public static final String PREF_UNIQUE_LOGIN = "login_unique";
public final static String USER_USERNAME = "username";
public final static String USER_WEBSITE = "website";

View file

@ -18,13 +18,35 @@ import com.newsblur.domain.UserDetails;
public class PrefsUtils {
public static void saveCookie(final Context context, final String cookie) {
public static void saveLogin(final Context context, final String userName, final String cookie) {
final SharedPreferences preferences = context.getSharedPreferences(PrefConstants.PREFERENCES, 0);
final Editor edit = preferences.edit();
edit.putString(PrefConstants.PREF_COOKIE, cookie);
edit.putString(PrefConstants.PREF_UNIQUE_LOGIN, userName + "_" + System.currentTimeMillis());
edit.commit();
}
/**
* Removes the current login session (i.e. logout)
*/
public static void clearLogin(final Context context) {
final SharedPreferences preferences = context.getSharedPreferences(PrefConstants.PREFERENCES, 0);
final Editor edit = preferences.edit();
edit.putString(PrefConstants.PREF_COOKIE, null);
edit.putString(PrefConstants.PREF_UNIQUE_LOGIN, null);
edit.commit();
}
/**
* Retrieves the current unique login key. This key will be unique for each
* login. If this login key doesn't match the login key you have then assume
* the user is logged out
*/
public static String getUniqueLoginKey(final Context context) {
final SharedPreferences preferences = context.getSharedPreferences(PrefConstants.PREFERENCES, 0);
return preferences.getString(PrefConstants.PREF_UNIQUE_LOGIN, null);
}
public static void saveUserDetails(final Context context, final UserDetails profile) {
final SharedPreferences preferences = context.getSharedPreferences(PrefConstants.PREFERENCES, 0);
final Editor edit = preferences.edit();