- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
tl;dr - At the bottom, I ask a couple general questions about smart database design that don't require reading the whole thing. So feel free to skip and take a look at those. Thanks!
我正在构建一个 Rails 网络应用程序,在用户输入一些内容后,我会生成许多选项,用户可以从中选择一个,然后将其保存并与用户相关联。这种选择可能会在选项生成后很长时间内出现——因此需要保存选项——但一旦做出选择,所有“不正确”的选项都不再相关。
我对数据库的工作原理和减慢速度的原因知之甚少,因此我非常感谢任何关于如何最好地实现这一目标的输入(如下所述),考虑到我在我想到的方法中看到的冲突.
在我看来,我可以采取三种途径:
让选项只是 Choice
模型的实例,通过 belongs_to
/has_many
与用户相关联。当用户选择一个时,它的 id
被声明为用户的 choice_id
(并且,其他选项可能与用户解除关联)。
The main issue with this that I see is the exponential increase in the size of the
Choice
table which would result. This is a major table in my app, and I would like to keep it as quick as possible.
在用户输入之后,我生成并保存比方说 5 个Choice
对象,所有这些对象都属于
用户,作为选项
.然后,当用户选择时,删除四个,第五个关联为该用户的单个选择
The downside, as I perceive it, is that I end up with lots of "empty" rows in the database, so that the highest
choice_id
is significantly greater than the number ofchoices
in the database. A boss I recently worked for gave the advice never to delete data, which obviously clashes with this approach.
我为 Option
模型创建了一个单独的表,它实际上在所有方面都与 Choice
模型相同,因为选项需要完全丰富的替身供您选择。这些选项 belong_to
a user
,如上所示,但当我选择毕业成为 choice
。
(这有点类似于 this older post's discussion of archiving by moving old data to a new table 。这被认为是一种好的做法吗?对我来说似乎很理想,但我不知道潜在的缺点)。
As I see it, this option preserves all data while keeping my main
Choice
table unencumbered by kruft unchosen data. Unfortunately, it adds a major duplication in the database, and a duplication of code as well (though I suppose I could haveOption
just inherit fromChoice
, which is weird, but whatever).
但是,所有这些意见都完全不了解数据库架构和效率方面的知识,如果我知道的话,我会觉得能够更好地权衡取舍:
表中已删除的行是否会像现有行一样减慢事务处理速度?较少的?完全没有?什么时候表大小成为 SQL 数据库中的一个严重问题?值得思考吗?
删除数据的最佳做法是什么?这真的是个坏主意吗?
关于重复表的最佳做法是什么? (即具有相同数据结构的表,由于多种原因,与原始表的处理方式不同)。
最广泛、最不恰当且最有帮助的问题:您将如何处理这个问题,优化 Choice
表的效率? (但也要尽可能避免重复并遵循最佳实践)。
谢谢!
最佳答案
一个以“.”为前缀的小文件怎么样?所以它被隐藏(在 unix 中)放置在用户主目录中。如果您以可读的格式输出您的选项,则可以轻松阅读和修改它们。
您只希望在性能或功能合理的情况下使用数据库。如果您要求用户使用必须安装的数据库,而客户可能不喜欢这样做。
关于sql - Rails 应用程序 - 最好保留或删除过时的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28573021/
我是非洲的一名学生,在我们的土地上,确实存在缓慢且昂贵的互联网连接,这就是为什么每当我们听到安装软件的“在线存储库”方法这个词时都会害怕得发抖。该死的,这通常意味着你必须去别处看看。 问题。(如果没有
我正在使用 OpenCV 1 进行一些图像处理,并且对 cvSetErrMode 函数(它是 CxCore 的一部分)感到困惑。 OpenCV 具有三种错误模式。 叶:调用错误处理程序后程序终止。 父
安装新版 IDEA.14 后,(maven)项目的部署显着增加(从 15 秒增加到 47 秒)。 最佳答案 原因: IDEA 使用 捆绑 Maven的版本 解决方案:设置 (ctrl+alt+S) -
在 .NET 中,您可以将某些方法标记为过时,以便开发人员在尝试使用已弃用的方法时收到警报。 Private Sub FormerMethod() 问题是您只能在您控制的类中执行此操作。当您希望开发
一段时间以来,我一直在尝试自己解决这个问题,但一直没有成功。当我大约有 10% 的时间重新部署我的 Rails 应用程序时,就会发生这种情况。其他 90% 的时间部署顺利进行。 我试了又试,还是没成功
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我正在学习 HTTP/2 协议(protocol)。它是一个带有小消息帧的二进制协议(protocol)。它允许在单个 TCP 连接上进行流复用。从概念上讲,它似乎与 WebSockets 非常相似。
在 Matlabs 的最新版本中,specgram 函数被 spectrogram 取代,文档说明: Note. To obtain the same results for the removed
我们试图在构建时标记外部类型(如 ConfigurationManager)的使用。 自定义代码分析字典可以提供帮助 [1],但仅限于项目中包含源代码的情况。同样,Obsolete 属性适用于项目中包
我将 Anaconda 与 Python 3 结合使用,并尝试安装 cc 包,这是 uber h3 包的要求。 尝试通过以下方式在 anaconda 命令行中安装时: pip install cc 我
我在 Razor 中创建了一个专门用于显示货币的显示模板,现在我想在我的代码中删除它并替换为接受字符串格式(我可以将其设置为“C”)的标准文本显示模板。 然而,出现了很多次,所以我想使用类似 [Obs
我希望我的网站具有如下所示的 URL: example.com/2010/02/my-first-post 我有我的 Post带 slug 的模型字段('我的第一篇文章')和 published_on
4.7 并喜欢在 qgraphicsview 上叠加两个图像。顶部的图像应是半透明的,以便能够透过它看到。最初,两个图像都是完全不透明的。我期望存在一些为每个像素设置全局 alpha 值的函数,但似乎
总结: 我在我的 Swift 代码中犯了一个错误,我已经修复了它。然后我问自己为什么会这样,我该如何避免。我尝试了一些方法,但没有任何帮助。 我把错误和我的想法放在下面。我希望你能教我避免这种错误的正
我正在尝试重命名在 SVN 中跟踪的 Java 包。这一切似乎都有效。它将代码移动到新包等。然而,噩梦就在那时开始,乐趣就开始了,这取决于你的观点。摆脱旧包很难。 我陷入了“过时”或“不存在”消息的循
我们使用 NLog 或 Serilog 进行日志记录。我们正忙于将系统从 ASP.NET 移植到 ASP.NET Core,这 has logging built in . 理想情况下,我们希望放弃
ETag header 的定义 ( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag ): The ETag HTTP re
我是一名优秀的程序员,十分优秀!