使用ORMapping后数据库设计的问题
之前系统中直接保存post的title和description, 在显示的时候要对title对一个strip操作,比如将Free Memory修改为free-memory,用于friendly url. 将description做截断用于列表中的显示.
现在发现这样是完全不靠谱的, 首先上面提到的两个运算会发生在每次请求过程中, 虽然可能耗时不多, 但是在一个开放的Web系统中这样的开销仍然是一种罪恶!
其次的问题发生在ORMapping的使用中, 参考typo的方法, Post model中有一个stripped_title的方法, 用于生成stripped title, 而产生的问题是今后我的操作必须严格依照object relationship, 无法进行SQL scale. 比如我想取所有的comments, 顺便要left join posts, 这样stripped title将无法得到….如果使用comment.post.stripped_title看似很爽,但是在log中很明显可以看出SQL多了几条, 这样的开销是不被允许的.
最后的办法就是在执行New, Update操作时一定要直接生成 stripped title, excerpt并保存在数据库中. 切记切记 TOT
Tags: activerecord, ormapping, rails
May 11th, 2007 at 8:03 am
[...] 相关主题 使用ORMapping后数据库设计的问题make excerpt in RubyRails Cachestring with argument in GetText of railsrender partialrails中的session存储问题rails中的select helperRailsbenchRails with Subversion (SVN) 06.12.4Rail处理Unicode问题Install RMagic on Mac OS X06.11.22利用Rails Freeze生成本地Rails DocRails with TextMate [...]