我应该使用平面文件还是数据库来存储 Android 上的随机报价应用程序的报价?
我正在 Android 上开发一个应用程序,它会从大量引言中随机挑选并显示鼓舞人心的引言(或诗句)。在 Android 上,我可以在平面文件和 SQLite 数据库之间进行选择。
该应用程序应满足以下条件:
可扩展至 10^6 引文和/或诗句
速度非常快(即检索并显示引文) ,立即按一下按钮)
能够从外部源加载新报价(以我的格式)尚未决定)
我必须使用什么数据格式?谢谢。
I am developing an app on Android that will randomly pick and display an inspirational quotation (or verse) from a large collection of quotations. On Android I can choose between a flat file and an SQLite database.
The app should satisfy the following conditions:
Be scalable to 10^6 quotations and/or verses
Be very fast (i.e. retrieve and display a quotation, immediately at the touch of a button)
Be able to load new quotations from an external source (in a format I have not yet decided)
What data format must I use? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会使用一个非常简单的数据库,单个表:
带有可能的“已查看”位字段,您可以更新该字段以防止重复。生成一个随机值并从表中选择该行,将其标记为已查看并完成操作。
平面文件的问题是快速查找并读取文件中间的引用。这就是数据库擅长的地方。另外,对于“平面”文件,文件行末尾会浪费大量空间。
另外,如果您可以加载新的报价,为什么要一次填充 10^6 呢?只需加载足够的内容以使应用程序继续运行并按顺序浏览它们,删除已查看的内容并加载新的内容。这种方法需要您跟踪最后加载的报价,因此您总是加载新的报价。
I'd go with a very simple database, single table:
with a possible "Viewed" bit field, that you can update to prevent duplicates. Generate a random value and select that row from the table, mark it viewed and be done with it.
The problem with a flat file is quickly finding and reading a quote from the middle of the file. This is what a database does well. Also with a "flat" file you'll have a lot of wasted space at the end of file lines.
Also, if you can load new quotes, why populate 10^6 at any one time? just load enough to keep the app going and march through them in a sequential order, deleting viewed ones and loading new ones. This approach would require you to keep track of the last loaded quote, so you are always loading new ones.