gpt4 book ai didi

algorithm - 分页算法实现协助

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:00:06 33 4
gpt4 key购买 nike

我正在编写一个分页算法,但我对最佳实现方式有些困惑。我已阅读有关使用 Offset 的文章以及发布新内容时的问题。替代方法是使用 seek 方法

那么我真正想要完成的是什么?我相信你们中的一些人可能听说过 Tinder。当您加载应用程序时,会出现一组卡片。这些卡片上写满了您可以喜欢或不喜欢的其他用户的信息。我假设在第一次调用时完成了一个带有限制的简单查询来检索用户。然而,在用户滑动几次后,应用程序发出越来越多的调用。我想做类似的事情。这是我当前的设置。

APP伪代码:

1) Lets say I have choose to load 10 cards initially.
2) User keeps swiping
3) When a user has 3 more cards left my app makes another call to the API and gets 10 more cards.
4) Repeat from step 2.

我在 API 端(不是应用端)的逻辑上遇到了一些问题。

1) User started the app and the API fetched initial 10 cards. When it comes
time for step 3, just making another call based on whom the user has
liked/disliked can load duplicates of the remaining 3 cards
2) If I choose to use offset, new users will mess up the pagination as a
duplicate will be loaded.

我认为我的第一个解决方案是使用一个临时表来存储已加载的用户。一旦用户喜欢/不喜欢一个人,该条目就会从该表中删除。此逻辑的问题在于,假设用户最初加载 10 张卡片,然后仅滑动 5 张并离开应用程序。现在我有 5 个用户存储在临时表中,不会为用户加载,因为它已经加载并且没有任何操作。此外还有额外的开销。

所以我的问题实际上是创建 API 的最佳方法是什么,该 API 允许我在不重复的情况下加载卡片。我认为一次加载一个效率不是很高(对服务器的调用太多)。最后一点:我不是直接从用户表中获取数据。我将用户带入算法中。该算法吐出一组 10 个用户。

如果您看完了这篇长文,我深表歉意。我只是想让你知道,我已经真诚地尝试提出一个解决方案,只是需要一点插入。

最佳答案

I thought my solution to number one is to have a temporary table that stores what users have been loaded. Once a user likes/dislikes a person, that entry gets removed from that table. The issue with this logic is that lets say a user loads 10 cards initially, then swipes on only 5 and leaves the app. Now I have 5 users stored in the temporary table that will not load for the user because it has already been loaded and there has been no action. Plus there is extra overhead

我想在您当前的方法问题中强调“离开应用程序”和“并且没有采取任何行动”。

如果当用户离开应用程序时您真的做了什么怎么办?

我的意思是,为了避免这个问题,你能不能(从临时表中)删除他没有看到的那5条剩余的临时记录?

通过阅读您的所有描述,您似乎可以通过这样做来解决它。

希望对您有所帮助。

关于algorithm - 分页算法实现协助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37368161/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com