我目前正在努力寻找最好的方法(在可用性和性能方面),当处理像获取使用特定标签或类别标记的记录之类的情况时。
一个不错的方法(我想用的方法)是用标签/类别段来获取记录,这样URL看起来就像这样:
http://stackoverflow.com/questions/tagged/language-agnostic通过slug拉取记录,看起来比:
http://stackoverflow.com/questions/tag/789/language-agnostic通过ID获取并在后面添加slug,因此它对搜索引擎更友好。这种方法在性能方面更好,因为通过整数ID获取数据比通过字符串获取数据更快。(cmiiw)
现在,使用如下的db模式:
posts post_to_tags tags
----- ------------ ----
id id id
title post_id name
content tag_id slug
... ...我做得对吗?有没有我需要知道的陷阱或最佳实践,以避免性能问题?(例如,标签不能超过10000条记录,或者标签段塞不能超过n个字符,或者其他)
提前谢谢。
发布于 2009-01-27 12:24:02
使用第一个URL样式和当前的db设计,您可以这样做:
select ...
from posts p
join posts_to_tags pt on pt.post_id = p.post_id
join tags t on t.id = pt.tag_id
where t.slug = [url slug value];只要对tags.slug进行了索引,这就应该是非常有效的,与
select ...
from posts p
join posts_to_tags pt on pt.post_id = p.post_id
where pt.tag_id = [url tag ID];发布于 2009-11-28 00:08:57
第一个更好,但是插件可能会被改变吗?在这种情况下,您需要有一个重定向表(例如,“关于狗的一些文章”现在是“关于狗和猫的文章”)。
https://stackoverflow.com/questions/482636
复制相似问题