英文:
Question on logic rather than specific programming issue
问题
如果不是在这里,哪里是正确的地方来提出这个问题?我正在创建一个网络应用程序,将托管涵盖不同主题的问题和答案。用户应该能够看到问题列表,并尝试回答他们喜欢的问题。然而,用户不应该在问题列表中看到他们已经回答过的问题。
我打算使用的技术栈是Express
,Node
,Mongo
。
我是否应该在应用程序中加入逻辑,以维护用户已回答的问题列表,并在查询数据库时排除已回答的问题,以不呈现给用户?我的担忧是这种解决方案可能难以扩展,并且可能会降低性能。
总之,如何正确实现一个用例,该用例仅向用户显示用户尚未看过的全局集合中的一部分值?
英文:
If not here, what would be the right place to ask this question? I am creating a web application which will host questions and answers covering different topics. A user should see list of questions and can attempt to answer the one they like. The user however should not see the question they have already answered in the list of questions.
The stack I intend to use is Express
, Node
, Mongo
.
Should I incorporate the logic in application which maintains list of questions answered by user and not present those questions to the user why excluding the answered questions when querying the database? My concern is this solution might be difficult to scale and could degrade performance.
In summary, what might be the right way to implement a use case which shows the users only a subset of values from a global set which the user has not already seen.
答案1
得分: 0
最简单的解决方案是将问题按原样存储,同时也将用户存储起来。
然后,在一个名为user_answers或类似的表/文档中存储用户和问题之间的关系。
你确实需要以某种方式存储这些关系,如果没有问题的话,你可以简单地将它们存储在数据库中。我建议你目前可以这样做,如果在性能方面出现扩展性问题,特别是在搜索方面,那么你可以为每个用户存储一个文件,文件位置可以通过用户、哈希值或类似的方式唯一确定,每当需要用户的答案时,只需在服务器端加载该文件,并将其中存在的问题ID添加到过滤器中。
因此,你实际上可以将这些存储为文件,加载它们就像打开一个文件一样简单,但如果我是你,我不会立刻这样做。我会简单地使用已经存在的数据库功能,一旦出现无法解决的问题,我才会将它们迁移到文件中。
这意味着你编写的任何代码都应该尽可能地不关心答案存储位置,如果可能的话,应该在一个地方指定这个位置,这样,如果你需要迁移这些数据,你将在编码方面更容易处理,并等待值实际上被移动。
英文:
The simplest solution would be to store the questions as they are and store the users as well.
Then, store the relations between user and question in a table/document called user_answers or something of the like.
You do need to store these relations somehow, which, if nothing's wrong, then you can simply store it in the database. And I suggest that you could do this for the time being and if it turns out to be scaling badly in terms of performance, particularly searching them, then you will be able to store a file for each user at a file location uniquely identifiable via the user, a hash or something and whenever the user's answers are needed, then simply load that file server-side and add the question ids present there into a filter.
So, you can actually store these as files and it would become as easy to load them as opening a file, but if I were you, I would not do this right away. I would simply use the db features already present and once this becomes unsolvable, then I would migrate them into files.
This means that any coding that you work should be as much agnostic to the whereabouts of the location of answers per user and, if possible that should be specified at a single place, so, if you need to migrate this, you will have an easy task in terms of coding and a wait upon the values being actually moved.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论