mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Splitting profiles and stories.
This commit is contained in:
parent
e6d1cd832c
commit
aa9197feb5
5 changed files with 21 additions and 17 deletions
|
@ -369,6 +369,7 @@ def load_single_feed(request, feed_id):
|
|||
page = int(request.REQUEST.get('page', 1))
|
||||
dupe_feed_id = None
|
||||
userstories_db = None
|
||||
user_profiles = {}
|
||||
now = localtime_for_timezone(datetime.datetime.now(), user.profile.timezone)
|
||||
|
||||
if page: offset = limit * (page-1)
|
||||
|
@ -387,7 +388,7 @@ def load_single_feed(request, feed_id):
|
|||
|
||||
stories = feed.get_stories(offset, limit)
|
||||
try:
|
||||
stories = MSharedStory.stories_with_comments(stories, user)
|
||||
stories, user_profiles = MSharedStory.stories_with_comments_and_profiles(stories, user)
|
||||
except redis.ConnectionError:
|
||||
logging.user(request, "~BR~FK~SBRedis is unavailable for shared stories.")
|
||||
|
||||
|
@ -474,6 +475,7 @@ def load_single_feed(request, feed_id):
|
|||
FeedLoadtime.objects.create(feed=feed, loadtime=timediff)
|
||||
|
||||
data = dict(stories=stories,
|
||||
user_profiles=user_profiles,
|
||||
feed_tags=feed_tags,
|
||||
feed_authors=feed_authors,
|
||||
classifiers=classifiers,
|
||||
|
|
|
@ -643,9 +643,10 @@ class MSharedStory(mongo.Document):
|
|||
return comments
|
||||
|
||||
@classmethod
|
||||
def stories_with_comments(cls, stories, user, check_all=False):
|
||||
def stories_with_comments_and_profiles(cls, stories, user, check_all=False):
|
||||
r = redis.Redis(connection_pool=settings.REDIS_POOL)
|
||||
friend_key = "F:%s:F" % (user.pk)
|
||||
profile_user_ids = set()
|
||||
for story in stories:
|
||||
if check_all or story['comment_count']:
|
||||
comment_key = "C:%s:%s" % (story['story_feed_id'], story['guid_hash'])
|
||||
|
@ -672,20 +673,18 @@ class MSharedStory(mongo.Document):
|
|||
story['share_count'] = r.scard(share_key)
|
||||
friends_with_shares = [int(f) for f in r.sinter(share_key, friend_key)]
|
||||
nonfriend_user_ids = list(set(story['share_user_ids']).difference(friends_with_shares))
|
||||
profiles = MSocialProfile.objects.filter(user_id__in=nonfriend_user_ids)
|
||||
profile_user_ids.update(nonfriend_user_ids)
|
||||
profile_user_ids.update(friends_with_shares)
|
||||
friend_profiles = []
|
||||
if friends_with_shares:
|
||||
friend_profiles = MSocialProfile.objects.filter(user_id__in=friends_with_shares)
|
||||
story['shared_by_public'] = []
|
||||
story['shared_by_friends'] = []
|
||||
for profile in profiles:
|
||||
story['shared_by_public'].append(profile.to_json(compact=True))
|
||||
for profile in friend_profiles:
|
||||
story['shared_by_friends'].append(profile.to_json(compact=True))
|
||||
story['shared_by_public'] = nonfriend_user_ids
|
||||
story['shared_by_friends'] = friends_with_shares
|
||||
story['share_count_public'] = story['share_count'] - len(friend_profiles)
|
||||
story['share_count_friends'] = len(friend_profiles)
|
||||
|
||||
return stories
|
||||
|
||||
profiles = MSocialProfile.objects.filter(user_id__in=list(profile_user_ids))
|
||||
profiles = [profile.to_json(compact=True) for profile in profiles]
|
||||
|
||||
return stories, profiles
|
||||
|
||||
|
||||
class MSocialServices(mongo.Document):
|
||||
|
|
|
@ -44,7 +44,7 @@ def load_social_stories(request, user_id, username=None):
|
|||
if not stories:
|
||||
return dict(stories=[])
|
||||
|
||||
stories = MSharedStory.stories_with_comments(stories, user, check_all=True)
|
||||
stories, profiles = MSharedStory.stories_with_comments_and_profiles(stories, user, check_all=True)
|
||||
|
||||
story_feed_ids = list(set(s['story_feed_id'] for s in stories))
|
||||
socialsub = MSocialSubscription.objects.get(user_id=user.pk, subscription_user_id=social_user_id)
|
||||
|
@ -144,7 +144,7 @@ def load_social_page(request, user_id, username=None):
|
|||
shared_date = localtime_for_timezone(story['shared_date'], social_user.profile.timezone)
|
||||
story['shared_date'] = format_story_link_date__long(shared_date, now)
|
||||
|
||||
stories = MSharedStory.stories_with_comments(stories, user, check_all=True)
|
||||
stories, profiles = MSharedStory.stories_with_comments_and_profiles(stories, user, check_all=True)
|
||||
social_profile = MSocialProfile.objects.get(user_id=social_user_id)
|
||||
|
||||
params = {
|
||||
|
@ -198,7 +198,7 @@ def mark_story_as_shared(request):
|
|||
story.count_comments()
|
||||
|
||||
story = Feed.format_story(story)
|
||||
story = MSharedStory.stories_with_comments([story], request.user)[0]
|
||||
story, profiles = MSharedStory.stories_with_comments_and_profiles([story], request.user)[0]
|
||||
|
||||
return {'code': code, 'story': story}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ NEWSBLUR.AssetModel.Reader = function() {
|
|||
this.classifiers = {};
|
||||
this.friends = {};
|
||||
this.profile = {};
|
||||
this.user_profiles = new NEWSBLUR.Collections.Users();
|
||||
this.starred_stories = [];
|
||||
this.starred_count = 0;
|
||||
this.read_stories_river_count = 0;
|
||||
|
@ -414,6 +415,9 @@ NEWSBLUR.AssetModel.Reader.prototype = {
|
|||
}
|
||||
});
|
||||
}
|
||||
if (data.user_profiles) {
|
||||
this.user_profiles.add(data.user_profiles);
|
||||
}
|
||||
$.isFunction(callback) && callback(data, first_load);
|
||||
}
|
||||
},
|
||||
|
|
|
@ -19,7 +19,6 @@ _.extend(NEWSBLUR.ReaderSocialProfile.prototype, {
|
|||
this.make_modal();
|
||||
this.open_modal();
|
||||
_.defer(_.bind(this.fetch_profile, this, user_id));
|
||||
// this.fetch_profile(user_id);
|
||||
|
||||
this.$modal.bind('click', $.rescope(this.handle_click, this));
|
||||
},
|
||||
|
|
Loading…
Add table
Reference in a new issue