mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Updating feed polling intervals. Also adding a progress bar to premium upgrading screen. Should make for a smoother transition for those high-feed subscribers.
This commit is contained in:
parent
f5e36c5b8e
commit
d0e25a0716
4 changed files with 33 additions and 19 deletions
|
@ -10,6 +10,7 @@ from utils import json_functions as json
|
|||
from paypal.standard.forms import PayPalPaymentsForm
|
||||
from utils.user_functions import ajax_login_required
|
||||
from apps.profile.models import Profile
|
||||
from apps.reader.models import UserSubscription
|
||||
|
||||
@login_required
|
||||
@require_POST
|
||||
|
@ -121,14 +122,22 @@ def profile_is_premium(request):
|
|||
retries = int(request.GET['retries'])
|
||||
profile = Profile.objects.get(user=request.user)
|
||||
|
||||
if retries > 3:
|
||||
subs = UserSubscription.objects.filter(user=request.user)
|
||||
total_subs = subs.count()
|
||||
activated_subs = subs.filter(active=True).count()
|
||||
|
||||
if retries > 30:
|
||||
subject = "Premium activation failed: %s (%s)" % (request.user, request.user.pk)
|
||||
message = "Check PayPalIPN"
|
||||
mail_admins(subject, message, fail_silently=True)
|
||||
code = -1
|
||||
request.user.profile.is_premium = True
|
||||
request.user.profile.save()
|
||||
|
||||
return {
|
||||
'is_premium': profile.is_premium,
|
||||
'code': code,
|
||||
'activated_subs': activated_subs,
|
||||
'total_subs': total_subs,
|
||||
}
|
||||
|
|
@ -595,31 +595,34 @@ class Feed(models.Model):
|
|||
if updates_per_day < 1 and self.num_subscribers > 2:
|
||||
updates_per_day = 1
|
||||
# 0 updates per day = 24 hours
|
||||
# 1 update per day = 6 hours
|
||||
# > 1 update per day:
|
||||
# 2 updates = 3 hours
|
||||
# 1 subscriber:
|
||||
# 1 update per day = 6 hours
|
||||
# 2 updates = 3.5 hours
|
||||
# 4 updates = 2 hours
|
||||
# 10 updates = 50 minutes
|
||||
# 10 updates = 80 minutes
|
||||
# 2 subscribers:
|
||||
# 1 update per day = 4.5 hours
|
||||
# 10 updates = 55 minutes
|
||||
updates_per_day_delay = 6 * 60 / max(.25, ((max(0, self.num_subscribers)**.55)
|
||||
* (updates_per_day**.85)))
|
||||
* (updates_per_day**.75)))
|
||||
|
||||
# Lots of subscribers = lots of updates
|
||||
# 144 hours for 0 subscribers.
|
||||
# 24 hours for 1 subscriber.
|
||||
# 6 hours for 2 subscribers.
|
||||
# 2.5 hours for 3 subscribers.
|
||||
# 15 min for 10 subscribers.
|
||||
subscriber_bonus = 24 * 60 / max(.167, self.num_subscribers**2)
|
||||
subscriber_bonus = subscriber_bonus / max(1, (10 * self.premium_subscribers))
|
||||
# 7 hours for 2 subscribers.
|
||||
# 3 hours for 3 subscribers.
|
||||
# 25 min for 10 subscribers.
|
||||
subscriber_bonus = 24 * 60 / max(.167, self.num_subscribers**1.75)
|
||||
subscriber_bonus = subscriber_bonus / max(1, (5 * self.premium_subscribers))
|
||||
|
||||
slow_punishment = 0
|
||||
if self.num_subscribers <= 1:
|
||||
if 30 <= self.last_load_time < 60:
|
||||
slow_punishment = self.last_load_time
|
||||
elif 60 <= self.last_load_time < 200:
|
||||
slow_punishment = 4 * self.last_load_time
|
||||
slow_punishment = 2 * self.last_load_time
|
||||
elif self.last_load_time >= 200:
|
||||
slow_punishment = 12 * self.last_load_time
|
||||
slow_punishment = 6 * self.last_load_time
|
||||
total = int(updates_per_day_delay + subscriber_bonus + slow_punishment)
|
||||
# print "[%s] %s (%s-%s), %s, %s: %s" % (self, updates_per_day_delay, updates_per_day, self.num_subscribers, subscriber_bonus, slow_punishment, total)
|
||||
random_factor = random.randint(0, total) / 4
|
||||
|
|
|
@ -22,8 +22,7 @@
|
|||
}
|
||||
|
||||
.NB-paypal-return .NB-paypal-return-loading {
|
||||
width: 220px;
|
||||
height: 19px;
|
||||
background: transparent url('../img/reader/spinner_bar.gif') no-repeat 0 0;
|
||||
margin: 18px auto 0;
|
||||
height: 16px;
|
||||
width: 300px;
|
||||
}
|
|
@ -13,13 +13,16 @@
|
|||
|
||||
detect_premium: function() {
|
||||
$.get('/profile/is_premium', {'retries': this.retries}, _.bind(function(resp) {
|
||||
if (resp.is_premium || resp.code < 0) {
|
||||
if (resp.activated_subs == resp.total_subs || resp.code < 0) {
|
||||
window.location.href = '/';
|
||||
} else if (!resp.is_premium) {
|
||||
} else if (resp.activated_subs != resp.total_subs) {
|
||||
this.retries += 1;
|
||||
_.delay(_.bind(function() {
|
||||
this.detect_premium();
|
||||
}, this), 3000);
|
||||
}, this), 2000);
|
||||
$('.NB-paypal-return-loading').progressbar({
|
||||
value: (resp.activated_subs / resp.total_subs) * 100
|
||||
});
|
||||
}
|
||||
}, this));
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue