新手问题 类似朋友圈,获取当前用户和用户所有朋友的文章的解决办法!

stephen · February 10, 2015 · Last by mogodb replied at February 12, 2015 · 2079 hits

我目前想到的是

创建一个数组a
current_user.topics放进数组a
current_user.friends do |friend|
    friend.topics放进数组a
end

然后根据创建时间排序数组a

最后返回数组a

请教下,有没有更优的办法?

  1. 把取文章的范围扩大,在显示中过滤
  2. 先得到要显示文章的 id,然后用 in 查询
  3. union 查询
  4. 为每个人设置 1 个 inbox,缓存管理
  5. 发文章和取文章的时候推拉结合,得到当前用户该看到的文章

可能这样子?

Topic.join(:creator).where('creator_id' => current_user.friends.pluck(:id).push(current_user.id)).order('updated_at desc')

可以试试 redis 的 zset

qq api 可以这么做么?

You need to Sign in before reply, if you don't have an account, please Sign up first.