mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Fixing interactions and activities to only pull what's necessary. Otherwise doubles show up in android + ios.
This commit is contained in:
parent
dd67f457d8
commit
4383b1148d
6 changed files with 30 additions and 18 deletions
|
@ -260,10 +260,11 @@ def stripe_form(request):
|
|||
def load_activities(request):
|
||||
user = get_user(request)
|
||||
page = max(1, int(request.REQUEST.get('page', 1)))
|
||||
activities = MActivity.user(user.pk, page=page)
|
||||
activities, has_next_page = MActivity.user(user.pk, page=page)
|
||||
|
||||
return {
|
||||
'activities': activities,
|
||||
'page': page,
|
||||
'has_next_page': has_next_page,
|
||||
'username': 'You',
|
||||
}
|
|
@ -1725,16 +1725,18 @@ class MInteraction(mongo.Document):
|
|||
}
|
||||
|
||||
@classmethod
|
||||
def user(cls, user_id, page=1):
|
||||
def user(cls, user_id, page=1, limit=None):
|
||||
user_profile = Profile.objects.get(user=user_id)
|
||||
dashboard_date = user_profile.dashboard_date or user_profile.last_seen_on
|
||||
page = max(1, page)
|
||||
limit = 4 # Also set in template
|
||||
limit = int(limit) if limit else 4
|
||||
offset = (page-1) * limit
|
||||
interactions_db = cls.objects.filter(user_id=user_id)[offset:offset+limit+1]
|
||||
has_next_page = len(interactions_db) > limit
|
||||
interactions_db = interactions_db[offset:offset+limit]
|
||||
with_user_ids = [i.with_user_id for i in interactions_db if i.with_user_id]
|
||||
social_profiles = dict((p.user_id, p) for p in MSocialProfile.objects.filter(user_id__in=with_user_ids))
|
||||
|
||||
|
||||
interactions = []
|
||||
for interaction_db in interactions_db:
|
||||
interaction = interaction_db.to_json()
|
||||
|
@ -1747,7 +1749,7 @@ class MInteraction(mongo.Document):
|
|||
interaction['is_new'] = interaction_db.date > dashboard_date
|
||||
interactions.append(interaction)
|
||||
|
||||
return interactions
|
||||
return interactions, has_next_page
|
||||
|
||||
@classmethod
|
||||
def new_follow(cls, follower_user_id, followee_user_id):
|
||||
|
@ -1881,17 +1883,20 @@ class MActivity(mongo.Document):
|
|||
}
|
||||
|
||||
@classmethod
|
||||
def user(cls, user_id, page=1, public=False):
|
||||
def user(cls, user_id, page=1, limit=4, public=False):
|
||||
user_profile = Profile.objects.get(user=user_id)
|
||||
dashboard_date = user_profile.dashboard_date or user_profile.last_seen_on
|
||||
page = max(1, page)
|
||||
limit = 4 # Also set in template
|
||||
limit = int(limit)
|
||||
offset = (page-1) * limit
|
||||
|
||||
activities_db = cls.objects.filter(user_id=user_id)
|
||||
if public:
|
||||
activities_db = activities_db.filter(category__nin=['star', 'feedsub'])
|
||||
|
||||
activities_db = activities_db[offset:offset+limit+1]
|
||||
has_next_page = len(activities_db) > limit
|
||||
activities_db = activities_db[offset:offset+limit]
|
||||
with_user_ids = [a.with_user_id for a in activities_db if a.with_user_id]
|
||||
social_profiles = dict((p.user_id, p) for p in MSocialProfile.objects.filter(user_id__in=with_user_ids))
|
||||
activities = []
|
||||
|
@ -1906,7 +1911,7 @@ class MActivity(mongo.Document):
|
|||
activity['with_user'] = social_profiles.get(activity_db.with_user_id)
|
||||
activities.append(activity)
|
||||
|
||||
return activities
|
||||
return activities, has_next_page
|
||||
|
||||
@classmethod
|
||||
def new_starred_story(cls, user_id, story_title, story_feed_id, story_id):
|
||||
|
|
|
@ -527,7 +527,7 @@ def profile(request):
|
|||
profile_ids = set(user_profile['followers_youknow'] + user_profile['followers_everybody'] +
|
||||
user_profile['following_youknow'] + user_profile['following_everybody'])
|
||||
profiles = MSocialProfile.profiles(profile_ids)
|
||||
activities = MActivity.user(user_id, page=1, public=True)
|
||||
activities, _ = MActivity.user(user_id, page=1, public=True)
|
||||
logging.user(request, "~BB~FRLoading social profile: %s" % user_profile['username'])
|
||||
|
||||
payload = {
|
||||
|
@ -873,12 +873,14 @@ def load_interactions(request):
|
|||
if not user_id:
|
||||
user_id = get_user(request).pk
|
||||
page = max(1, int(request.REQUEST.get('page', 1)))
|
||||
interactions = MInteraction.user(user_id, page=page)
|
||||
limit = request.REQUEST.get('limit')
|
||||
interactions, has_next_page = MInteraction.user(user_id, page=page, limit=limit)
|
||||
format = request.REQUEST.get('format', None)
|
||||
|
||||
data = {
|
||||
'interactions': interactions,
|
||||
'page': page,
|
||||
'has_next_page': has_next_page
|
||||
}
|
||||
|
||||
if format == 'html':
|
||||
|
@ -898,12 +900,14 @@ def load_activities(request):
|
|||
|
||||
public = user_id != request.user.pk
|
||||
page = max(1, int(request.REQUEST.get('page', 1)))
|
||||
activities = MActivity.user(user_id, page=page, public=public)
|
||||
limit = request.REQUEST.get('limit')
|
||||
activities, has_next_page = MActivity.user(user_id, page=page, limit=limit, public=public)
|
||||
format = request.REQUEST.get('format', None)
|
||||
|
||||
data = {
|
||||
'activities': activities,
|
||||
'page': page,
|
||||
'has_next_page': has_next_page,
|
||||
'username': (user.username if public else 'You'),
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<h5 class="NB-module-header">
|
||||
<div class="NB-module-header-right">
|
||||
<div class="NB-spinner NB-left"></div>
|
||||
<a href="#" class="NB-module-direction NB-module-next-page NB-javascript {% if activities|length <= 4 %}NB-disabled{% endif %}"></a>
|
||||
<a href="#" class="NB-module-direction NB-module-next-page NB-javascript {% if not has_next_page %}NB-disabled{% endif %}"></a>
|
||||
<a href="#" class="NB-module-direction NB-module-previous-page {% if page <= 1 %}NB-disabled{% endif %}"></a>
|
||||
</div>
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
|||
{% endif %}
|
||||
|
||||
<ul class="NB-interactions">
|
||||
{% for activity in activities|slice:":4" %}
|
||||
{% for activity in activities %}
|
||||
<li class="NB-interaction NB-activity-{{ activity.category }} {% if activity.is_new %}NB-highlighted{% endif %}"
|
||||
{% if activity.content_id %}data-content-id="{{ activity.content_id }}"{% endif %}
|
||||
{% if activity.feed_id %}data-feed-id="{{ activity.feed_id }}"{% endif %}
|
||||
|
|
|
@ -5,14 +5,14 @@
|
|||
<h5 class="NB-module-header">
|
||||
<div class="NB-module-header-right">
|
||||
<div class="NB-spinner NB-left"></div>
|
||||
<a href="#" class="NB-module-direction NB-module-next-page NB-javascript {% if interactions|length <= 4 %}NB-disabled{% endif %}"></a>
|
||||
<a href="#" class="NB-module-direction NB-module-next-page NB-javascript {% if not has_next_page %}NB-disabled{% endif %}"></a>
|
||||
<a href="#" class="NB-module-direction NB-module-previous-page {% if page <= 1 %}NB-disabled{% endif %}"></a>
|
||||
</div>
|
||||
Interactions
|
||||
</h5>
|
||||
|
||||
<ul class="NB-interactions">
|
||||
{% for interaction in interactions|slice:":4" %}
|
||||
{% for interaction in interactions %}
|
||||
<li class="NB-interaction NB-interaction-{{ interaction.category }}
|
||||
{% if interaction.is_new %}NB-highlighted{% endif %}
|
||||
{% if interaction.category == 'story_reshare' %}NB-interaction-sharedstory{% endif %}"
|
||||
|
|
|
@ -45,24 +45,26 @@ def render_recommended_users(context):
|
|||
@register.inclusion_tag('reader/interactions_module.xhtml', takes_context=True)
|
||||
def render_interactions_module(context, page=1):
|
||||
user = get_user(context['user'])
|
||||
interactions = MInteraction.user(user.pk, page)
|
||||
|
||||
interactions, has_next_page = MInteraction.user(user.pk, page)
|
||||
|
||||
return {
|
||||
'user': user,
|
||||
'interactions': interactions,
|
||||
'page': page,
|
||||
'has_next_page': has_next_page,
|
||||
'MEDIA_URL': context['MEDIA_URL'],
|
||||
}
|
||||
|
||||
@register.inclusion_tag('reader/activities_module.xhtml', takes_context=True)
|
||||
def render_activities_module(context, page=1):
|
||||
user = get_user(context['user'])
|
||||
activities = MActivity.user(user.pk, page)
|
||||
activities, has_next_page = MActivity.user(user.pk, page)
|
||||
|
||||
return {
|
||||
'user': user,
|
||||
'activities': activities,
|
||||
'page': page,
|
||||
'has_next_page': has_next_page,
|
||||
'username': 'You',
|
||||
'MEDIA_URL': context['MEDIA_URL'],
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue