Firebase Firestore 结构,用于获取不可见的热门帖子 - 社交 [英] Firebase Firestore Structure for getting un-seen trending posts - Social

查看:11
本文介绍了Firebase Firestore 结构,用于获取不可见的热门帖子 - 社交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是当前的示例结构

Posts(Collection)
    - post1Id : {
          viewCount : 100,
          likes     : 45,
          points    : 190,
          title     : "Title",
          postType  : image/video
          url       : FileUrl,
          createdOn : Timestamp,
          createdBy : user20Id,
          userName  : name,
          profilePic: url
      }
Users(Collection)
    - user1Id(Document):{
          postsCount : 10,
          userName  : name,
          profilePic : url
      }
        viewed(Collection)
            - post1Id(Document):{
                  viewedTime : ""
              }
                 
    - user2Id(Document)

最终目标是

  • 我需要获取当前用户未查看的帖子,并按分页降序排列.

可能的最佳解决方案是什么(例如更改结构、云功能、来自客户端的多个查询)?

What are the possible optimal solutions(like changing structure, cloud functions, multiple queries from client-side)?

推荐答案

我正在研究一种解决方案,以显示热门帖子并消除用户已经看到的帖子或内容不佳的帖子.处理两个查询真的很痛苦,尤其是在用户群增加的情况下.很难保持已查看"的内容.收集和过滤新帖子.想象一下,有 100 万条帖子被浏览过,然后过滤掉未看到的帖子.

I'm working on a solution to show trending posts and eliminate posts that are already seen by users or poor content. It's really painful to deal with two queries especially when the user base is increasing. It's difficult to maintain the "viewed" collection and filter the new posts. Imagine having 1 million viewed posts and then filter for the un-seen posts.

所以我想出了一个解决方案,虽然不是很好,但仍然很酷.

So I figured a solution, which is not that great, but still cool.

这是我们的数据结构

帖子(收藏)--postid(文件)

posts(Collection) --postid(document)

  1. 标题.
  2. 说明.
  3. 图片.
  4. 时间戳.
  5. 优先事项

这是一个带有基本细节的简单帖子结构.您可以看到我添加了一个优先级字段.这个领域会发挥作用.

This is a simple post structure with basic details. You can see I have added a Priority field. This field will do the magic.

如何使用优先权.

  1. 我们应该查询以较高优先级开始并以较低优先级结束的帖子.
  2. 当用户发布新帖子时.将当前时间戳指定为默认优先级.
  3. 当用户对帖子点赞(赞)时,优先级会增加 1 分钟(60000 毫秒)
  4. 当用户不喜欢(不喜欢)帖子时,优先级会降低 1 分钟(60000 毫秒)
  5. 您可以每 24 小时重置一次优先级.如果您今天早上开始浏览提要,您将看到过去 24 小时内的帖子.一旦达到 24 小时持续时间,您可以将优先级重置为当前时间.可以根据您的需要更改 24 小时限制.您可能希望每 15 分钟重置一次限制.因为每 15 分钟可能会添加 100 条新帖子.此限制将确保 Feed 中的内容重复.

因此,当您开始滚动提要时,您将首先获得所有热门帖子,然后再获得优先级较低的帖子.如果您今天发布帖子并且人们开始对其进行投票.它将获得更长的生命周期,从而压制糟糕的内容,当您对它投反对票时,只要用户无法访问它,它就会将帖子推下.

So when you start scrolling the feed you will get all the trending posts first then lower priority posts later. If you post a post today and people start upvoting it. It will get an increased lifetime, thus overpowers the poor content and when you downvote it, it will push down the post as long as users will not reach it.

使用时间戳作为优先级,因为旧帖子会随着时间的推移而失去优先级.即使是今天的热门帖子明天也应该失去优先级.

Using timestamp as a priority because the old posts should lose priority with time. Even the trending posts today should lose the priority tomorrow.

需要考虑的事项:

使用寿命可以根据您的需要而有所不同.用户群越大.你应该降低生命周期价值.因为如果今天发布的帖子被 10,000 名用户点赞,它会在未来 6.9 天趋势.如果有超过 100 个帖子被 10,000 多个用户点赞,那么在这 6.9 天内您将永远看不到新帖子.因此,热门帖子应该不会持续一两天.

The lifetime can vary according to your needs. The bigger the user base. You should lower the lifetime value. because if a post posted today is upvoted by 10,000 users it trends 6.9 days in the future. And if there are more than 100 posts that have been upvoted by more than 10,000 users then you will never get to see a new post in those 6.9 days. So a trending post should hardly last a day or two.

因此,在这种情况下,您可以提供 10 秒的生命周期,10,000 个点赞的生命周期为 1.1 天.

So in this case you can give 10 seconds lifetime, it will give 1.1 day lifetime for 10,000 upvotes.

这不是一个完美的解决方案,但可以帮助您入门.

This is not a perfect solution but it may help you get started.

这篇关于Firebase Firestore 结构,用于获取不可见的热门帖子 - 社交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆