模型 +数据库设计

发布于 2024-11-01 14:46:47 字数 892 浏览 0 评论 0原文

我想要完成的任务:

  • 图像应该是单个或在相册中
  • 可浏览的相册列表和带有页码的单张图片
  • 在浏览时不显示相册内的图像,仅显示相册封面

到目前为止我的方法是:

  • 代表单个图像的模型,和单个专辑
  • 一张数据库表内容,包含 id、标题、thumbnailFile 和 imageFile 等。
  • 一张数据库表专辑,包含专辑 id、专辑标题等。
  • 一张数据库表 album_content 映射哪个专辑内包含什么内容。
  • 一张数据库表使用专辑 id 进行浏览,以及不在相册内的内容的 ids + 用于缩略图预览和排序的复制属性(文件名、标题、视图、日期等)
  • 分页器仅使用后一个表,而视图则使用指向内容表的模型

我不认为上述情况就速度而言太糟糕了,但我觉得它不是特别优雅,我正在寻找更好的方法来做到这一点,并希望减少要缓存/无效的元素数量。到目前为止,我一直在思考以下内容:

  1. 数据库中只有一份数据副本(以某种方式组合内容、相册和浏览,并且仍然能够按日期、视图等快速对数据集进行计数和排序)
  2. 。来自任何可排序/按列排序的连接
  3. 将所有图像视为单个模型实例,也在相册内

我的主要问题是相册具有日期,视图等,独立于其中的内容,并且我希望按日期排序不在相册内的内容 + 相册的日期应具有唯一标识符。相册还包含与内容无关的列。

有没有好的办法解决这个问题呢?

*编辑:为了速度,我想我坚持使用单独的浏览表。有没有办法让 Zend dbTable 引用 browser <-> 的视图列专辑和内容,以便专辑或内容中的 onUpdate 利用 Zend 中的 CASCADE 逻辑来更新两个表?

What I want to accomplish:

  • Images that should be either single or in albums
  • Browseable list of albums and single pictures with page numbering
  • Not show images inside albums on browse, only album cover

My approach so far has been:

  • Models that represent a single image, and single album
  • One database table content containing id, title, thumbnailFile and imageFile etc.
  • One database table album with album id, album title etc.
  • One database table album_content mapping what content is inside what album
  • One database table browse with ids for albums, and ids for content not inside album + copied attributes used for thumbnail preview and sorting (filenames,titles,views,date etc.)
  • Paginator utilizing the latter table only, while view is utilizing the model pointing to content table

I don't think the above is too bad regarding speed, but I don't find it particulary elegant, and I'm looking for a better way to do it, and hopefully shrink the amount of elements to cache/invalidate. So far I've been thinking something along the lines of:

  1. Only having one copy of data in the database (combine content, album and browse somehow and still be able to quicly count and sort the dataset by date,views etc.)
  2. Stay away from joins on any sortable/order by column
  3. Treat all images as a single model instance, also inside albums

My main problem here is that albums have dates, views etc. independant of the content inside it, and I wish to order by the date of content not inside albums + the date of albums which should have a unique identifier. Albums also have colums not relevant for content.

Is there a good way to solve this?

*Edit: For speed, I think I'm stuck with the separate browse table. Is there a way to have Zend dbTable reference the view column of browse <-> album and content so that onUpdate in either album or content is utilizing the CASCADE logic in Zend to update both tables?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

野侃 2024-11-08 14:46:47

我会在后台编码:1 张单张图像 = 1 张输入为单张的专辑。因此,浏览单个图像与浏览相册相同。唯一的区别是当您显示“单图像”相册或“普通”相册时。
这是有道理的,因为专辑和单个图像都有一张图像代表内容(图像或封面)。

表可以是这样的:

t_album (id, type, title, cover_id, ...)
t_image (id, link, thumbnail_id, ...)
t_album_contents (id_album, id_image, comments)

请注意,仅当图像可能位于多个相册中或可能在同一相册中多次出现时,表 [t_album_contents] 才是必需的。否则,该表可能会消失并被表 [t_image] 中 [t_album] 上的外键替换。

I would code in backstage : 1 single image = 1 album typed as single. Thus browsing through single images is the same as browsing through albums. The only difference is when you display a "single image" album or a "normal" album.
It makes sens since both albums and single image has one image the represent the contents (the image or the cover).

Tables could like this:

t_album (id, type, title, cover_id, ...)
t_image (id, link, thumbnail_id, ...)
t_album_contents (id_album, id_image, comments)

Note that table [t_album_contents] is necessary only if an image may be in several albums or may be several times in the same album. Otherwise this table may disappear and be replaced with a foreign key on [t_album] in table [t_image].

乖乖 2024-11-08 14:46:47

首先坚持使用规范化数据库 (3NF) 总是一个好主意,然后根据您使用的 DBMS 进行运行时优化(只有在确实必须时才违反 3NF)...

再说一遍,我无法明确这一点足够了:以任何可接受的成本避免违反 3NF

如果您添加违反 3NF 的内容,请确保数据库的 3NF 部分在每种可能的情况下保持完整......您的冗余“复制属性”可能会导致数据不一致,因此确保模型的无冗余 3NF 部分中的数据具有优先级......例如。当服务器负载允许时,定期从 3NF 部分重建冗余部分,或者提供经过测试的更新模式,确保更新仅应用于 3NF 部分,并且 3NF 部分上的每次更新都会触发相应冗余数据的重建...当您出于性能等原因需要冗余数据时,这样的方法会尝试最大程度地降低数据损坏的风险,同时从数据库读取数据,

将数据库的 3NF 部分与其他部分分开(通过命名空间/前缀/等)也是一个好主意

取决于预期的请求(浏览请求的数量与更新/插入请求的数量)无论是否使用冗余数据,使用您建议的方法都是有意义的。当谈到速度时,不要低估正确的表索引。

对于比较(排序)与其他内容混合的专辑的问题:

为什么内容实体不能代表专辑?专辑就像一个目录...它可以有子目录,从目录的角度来看,这些子目录是内容...如果以这种方式建模,您将比较内容与内容...额外的属性,取决于特定的内容类型可以位于具有 1:0-1 关系的另一个表中,而“公共”可比较属性驻留在内容表中,

另一方面,您可以使用 union vor this ,理想情况下只会慢一点,但可以使两种类型的实体统一进行比较和排序...取决于预期的请求为每个可浏览对象缓存这些排序结果是有意义的,

我希望这会有所帮助

it's allways a good idea to stick to a normalized database (3NF) first, and the do runtime optimization based on the DBMS you use (violate 3NF only if you really have to) ...

again, i can't make this point clear enough: avoid violations of 3NF at any acceptable cost

if you add something that violates 3NF, make sure that the 3NF part of your database remains intact in every possible situation ... your redundant "copied attributes" could lead to inconsistant data, therefore make sure that the data in the redundancy free 3NF part of your model has the priority ... eg. regulary rebuild redundant parts from 3NF parts when server-load allows it or provide a tested update schema that makes sure that updates are ONLY applied to the 3NF part, and every update on the 3NF part triggers a rebuild of the corresponding redundant data ... approaches like this try to minimize the risk of data corruption when you need redundant data for reasons like performance while reading from the db

it's also a good idea to seperate the 3NF part of the DB from the other part (by namespace/prefix/etc)

depending on the expected request (# of browse-request vs. # of update-/insert-requests) it could make sense to use your suggested approach with redundant data or not. don't underestimate the right table index when it comes to speed.

for the problem of comparing (sorting) albums mixed with other content:

why can't a content entity represent an album? an album is like a directory ... it could have subdirectories which would be content from the directories point of view ... if it's modelled this way you would compare content to content ... extra attributes, depending on the particular content type can be in another table with a 1:0-1 relation while the "common" comparable attributes reside in the content table

on the other hand you could use a union vor this which would ideally be only a little slower but could make both types of entities uniform to be compared and sorted ... depending on the expected requests it could make sense to cache those sorted results for every browsable object

i hope this helps a bit

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文