Syncing redis on premium upgrade to sync new unread date possibilities for archive users.

This commit is contained in:
Samuel Clay 2022-01-13 16:56:30 -05:00
parent 1dd921fa61
commit 2792e7305a
8 changed files with 17 additions and 31 deletions

View file

@ -32,7 +32,10 @@ nb: pull
- docker exec newsblur_web ./manage.py loaddata config/fixtures/bootstrap.json - docker exec newsblur_web ./manage.py loaddata config/fixtures/bootstrap.json
coffee: coffee:
- coffee -c -w **/*.coffee - coffee -c -w **/*.coffee
migrations:
- docker exec -it newsblur_web ./manage.py makemigrations
migrate:
- docker exec -it newsblur_web ./manage.py migrate
shell: shell:
- docker exec -it newsblur_web ./manage.py shell_plus - docker exec -it newsblur_web ./manage.py shell_plus
bash: bash:

View file

@ -46,6 +46,7 @@ class Profile(models.Model):
view_settings = models.TextField(default="{}") view_settings = models.TextField(default="{}")
collapsed_folders = models.TextField(default="[]") collapsed_folders = models.TextField(default="[]")
feed_pane_size = models.IntegerField(default=242) feed_pane_size = models.IntegerField(default=242)
days_of_unread = models.IntegerField(default=settings.DAYS_OF_UNREAD)
tutorial_finished = models.BooleanField(default=False) tutorial_finished = models.BooleanField(default=False)
hide_getting_started = models.BooleanField(default=False, null=True, blank=True) hide_getting_started = models.BooleanField(default=False, null=True, blank=True)
has_setup_feeds = models.BooleanField(default=False, null=True, blank=True) has_setup_feeds = models.BooleanField(default=False, null=True, blank=True)
@ -71,7 +72,7 @@ class Profile(models.Model):
@property @property
def unread_cutoff(self, force_premium=False, force_archive=False): def unread_cutoff(self, force_premium=False, force_archive=False):
if self.is_archive or force_archive: if self.is_archive or force_archive:
return datetime.datetime.utcnow() - datetime.timedelta(days=settings.DAYS_OF_UNREAD_ARCHIVE) return datetime.datetime.utcnow() - datetime.timedelta(days=self.days_of_unread)
if self.is_premium or force_premium: if self.is_premium or force_premium:
return datetime.datetime.utcnow() - datetime.timedelta(days=settings.DAYS_OF_UNREAD) return datetime.datetime.utcnow() - datetime.timedelta(days=settings.DAYS_OF_UNREAD)

View file

@ -1160,10 +1160,10 @@ class RUserStory:
message = None message = None
if story.story_date < user.profile.unread_cutoff: if story.story_date < user.profile.unread_cutoff:
if user.profile.is_archive: if user.profile.is_archive:
message = "Story is more than %s days old, cannot mark as unread." % ( message = "Story is more than %s days old, change your days of unreads under Preferences." % (
settings.DAYS_OF_UNREAD_ARCHIVE) user.profile.days_of_unread)
elif user.profile.is_premium: elif user.profile.is_premium:
message = "Story is more than %s days old, cannot mark as unread." % ( message = "Story is more than %s days old. Premium Archive accounts can mark any story as unread." % (
settings.DAYS_OF_UNREAD) settings.DAYS_OF_UNREAD)
elif story.story_date > user.profile.unread_cutoff_premium: elif story.story_date > user.profile.unread_cutoff_premium:
message = "Story is more than %s days old. Premium accounts can mark unread up to %s days, and Premium Archive accounts can mark any story as unread." % ( message = "Story is more than %s days old. Premium accounts can mark unread up to %s days, and Premium Archive accounts can mark any story as unread." % (

View file

@ -656,6 +656,7 @@ class Feed(models.Model):
def setup_feed_for_premium_subscribers(self): def setup_feed_for_premium_subscribers(self):
self.count_subscribers() self.count_subscribers()
self.set_next_scheduled_update(verbose=settings.DEBUG) self.set_next_scheduled_update(verbose=settings.DEBUG)
self.sync_redis()
def check_feed_link_for_feed_address(self): def check_feed_link_for_feed_address(self):
@timelimit(10) @timelimit(10)

View file

@ -163,26 +163,6 @@ _.extend(NEWSBLUR.ReaderPreferences.prototype, {
'Timezone' 'Timezone'
]) ])
]), ]),
$.make('div', { className: 'NB-preference NB-preference-ssl' }, [
$.make('div', { className: 'NB-preference-options' }, [
$.make('div', [
$.make('input', { id: 'NB-preference-ssl-1', type: 'radio', name: 'ssl', value: 0 }),
$.make('label', { 'for': 'NB-preference-ssl-1' }, [
'Use a standard connection'
])
]),
$.make('div', [
$.make('input', { id: 'NB-preference-ssl-2', type: 'radio', name: 'ssl', value: 1 }),
$.make('label', { 'for': 'NB-preference-ssl-2' }, [
$.make('img', { src: NEWSBLUR.Globals.MEDIA_URL+'/img/icons/circular/g_icn_lock.png' }),
'Only use a secure https connection'
])
])
]),
$.make('div', { className: 'NB-preference-label'}, [
'SSL'
])
]),
$.make('div', { className: 'NB-preference NB-preference-showunreadcountsintitle' }, [ $.make('div', { className: 'NB-preference NB-preference-showunreadcountsintitle' }, [
$.make('div', { className: 'NB-preference-options' }, [ $.make('div', { className: 'NB-preference-options' }, [
$.make('div', [ $.make('div', [

View file

@ -20,7 +20,7 @@ SESSION_COOKIE_DOMAIN = 'localhost'
DOCKERBUILD = True DOCKERBUILD = True
DEBUG = False DEBUG = False
DEBUG = True # DEBUG = True
# DEBUG_ASSETS controls JS/CSS asset packaging. Turning this off requires you to run # DEBUG_ASSETS controls JS/CSS asset packaging. Turning this off requires you to run
# `./manage.py collectstatic` first. Turn this on for development so you can see # `./manage.py collectstatic` first. Turn this on for development so you can see
@ -33,7 +33,7 @@ DEBUG_ASSETS = True
# down verbosity. # down verbosity.
DEBUG_QUERIES = DEBUG DEBUG_QUERIES = DEBUG
DEBUG_QUERIES_SUMMARY_ONLY = True DEBUG_QUERIES_SUMMARY_ONLY = True
DEBUG_QUERIES_SUMMARY_ONLY = False # DEBUG_QUERIES_SUMMARY_ONLY = False
MEDIA_URL = '/media/' MEDIA_URL = '/media/'
IMAGES_URL = '/imageproxy' IMAGES_URL = '/imageproxy'

View file

@ -764,7 +764,6 @@ REDIS_POOL = redis.ConnectionPool(host=REDIS_USER['host'], port=
REDIS_ANALYTICS_POOL = redis.ConnectionPool(host=REDIS_USER['host'], port=REDIS_PORT, db=2, decode_responses=True) REDIS_ANALYTICS_POOL = redis.ConnectionPool(host=REDIS_USER['host'], port=REDIS_PORT, db=2, decode_responses=True)
REDIS_STATISTICS_POOL = redis.ConnectionPool(host=REDIS_USER['host'], port=REDIS_PORT, db=3, decode_responses=True) REDIS_STATISTICS_POOL = redis.ConnectionPool(host=REDIS_USER['host'], port=REDIS_PORT, db=3, decode_responses=True)
REDIS_FEED_UPDATE_POOL = redis.ConnectionPool(host=REDIS_USER['host'], port=REDIS_PORT, db=4, decode_responses=True) REDIS_FEED_UPDATE_POOL = redis.ConnectionPool(host=REDIS_USER['host'], port=REDIS_PORT, db=4, decode_responses=True)
# REDIS_STORY_HASH_POOL2 = redis.ConnectionPool(host=REDIS_USER['host'], port=REDIS_PORT, db=8) # Only used when changing DAYS_OF_UNREAD
REDIS_STORY_HASH_TEMP_POOL = redis.ConnectionPool(host=REDIS_USER['host'], port=REDIS_PORT, db=10, decode_responses=True) REDIS_STORY_HASH_TEMP_POOL = redis.ConnectionPool(host=REDIS_USER['host'], port=REDIS_PORT, db=10, decode_responses=True)
# REDIS_CACHE_POOL = redis.ConnectionPool(host=REDIS_USER['host'], port=REDIS_PORT, db=6) # Duped in CACHES # REDIS_CACHE_POOL = redis.ConnectionPool(host=REDIS_USER['host'], port=REDIS_PORT, db=6) # Duped in CACHES
REDIS_STORY_HASH_POOL = redis.ConnectionPool(host=REDIS_STORY['host'], port=REDIS_PORT, db=1, decode_responses=True) REDIS_STORY_HASH_POOL = redis.ConnectionPool(host=REDIS_STORY['host'], port=REDIS_PORT, db=1, decode_responses=True)

View file

@ -914,9 +914,11 @@ class FeedFetcherWorker:
logging.debug(" ***> [%-30s] ~BMRedis is unavailable for real-time." % (feed.log_title[:30],)) logging.debug(" ***> [%-30s] ~BMRedis is unavailable for real-time." % (feed.log_title[:30],))
def count_unreads_for_subscribers(self, feed): def count_unreads_for_subscribers(self, feed):
subscriber_expire = datetime.datetime.now() - datetime.timedelta(days=settings.SUBSCRIBER_EXPIRE)
user_subs = UserSubscription.objects.filter(feed=feed, user_subs = UserSubscription.objects.filter(feed=feed,
active=True, active=True,
user__profile__last_seen_on__gte=feed.unread_cutoff)\ user__profile__last_seen_on__gte=subscriber_expire)\
.order_by('-last_read_date') .order_by('-last_read_date')
if not user_subs.count(): if not user_subs.count():