Merb/DataMapperをしばらく使っていたのですが、
少なくともバージョン0.9.10, 0.9.11では、
associationの実装にバグがあり、
レコード数が多いテーブルがあると、aggregation系の処理に時間がかかるという問題がある事が分かりました。

例えば、Post.has n, :comments な関係がある時に、
以下のようなコードを実行すると、このようになります。

ruby>>
?> Post.first.comments.count #=> 188
~ (0.000865) SELECT "id" FROM "posts" ORDER BY "id" LIMIT 1
~ (0.000094) SELECT "id", "post_id" FROM "comments" WHERE ("post_id" IN (1)) ORDER BY "id"
~ (0.000063) SELECT COUNT(*) FROM "comments" WHERE ("post_id" = 1)
<<--

2つ目のSQLは不要なのですが、発行されてしまいます。
例えばCommentのレコード数が多かった場合、Commentオブジェクトを大量に生成しようとしてしまうため、致命的な遅さになってしまいます。

目下この問題の解決策を探しているところですが、
Edge-DMのspec/仕様でerrorが出ている状態なので、なかなか手が付けられない感じです。
とりあえず、dm-coreのassociations/relationship.rbの中の、

ruby>>
# @api private
def get_children(parent, options = {}, finder = :all, *args)
parent_value = parent_key.get(parent)
bind_values = [ parent_value ]

    with_repository(child_model) do |r|
      parent_identity_map = parent.repository.identity_map(parent_model)

      query_values = parent_identity_map.keys
      bind_values = query_values unless query_values.empty?
      query = child_key.zip(bind_values.transpose).to_hash
      collection = child_model.send(finder, *(args.dup << @query.merge(optio

ns).merge(query)))

      return collection unless collection.kind_of?(Collection) && collection.any?

<<--

の最後の collection.any? で件のSQLが実行されているところまでは分かりました。
DataMapper::CollectionはextlibのLazyArrayを継承しているクラスなのですが、どうもそのへんの仕様が変わったのに追従できてないのかな。
モジュールを過度に分散しすぎるのも、整合性を保つのが大変になるという問題がありますね。
注意深く完全なSpecを書く事を心がけていれば防げる問題かもしれないですが。

posted by genki genki on Wed 8 Apr 2009 at 04:52 with 0 comments
Contents rssrss
光ファイバーを二次元振動させて走査するAR用ディスプレイ
因果の取り違え
Swift2's defer for CoffeeScript
mongodb-3.0からcreateIndexのdropDupsが無くなったらしい
mongodb-3.0以降のWiredTigerの設定を動的に変更する方法
一般楕円の高速生成アルゴリズムへの道標
farro mantecatoのレシピ
Droonga関連の記事のまとめ
RuntimeErrorの特定のメッセージに限定してrescueする方法
jQueryでscriptタグを実行せずにappendする
Tags
coffeescriptdefergroongajsmemonodenodejs
Comments rssrss
http://mkbfab.com/bbs/board.php?bo_table=31&wr_id=93169 http://mkbfab.com/bbs/board.php?bo_table=31&wr_id=93169: Kaizenaire.сom stands out іn supplying promotions ... 05/25 03:10
https://blanksnowboards.com/quickwin-ios-win-big-now-easy-app-download/ https://blanksnowboards.com/quickwin-ios-win-big-now-easy-app-download/: Good read. 05/24 21:53
https://www.thegameroom.org/de/online-casinos/eu-lizenz/ https://www.thegameroom.org/de/online-casinos/eu-lizenz/: Транслируйте контент для взрослых безопасно, выбир... 05/24 21:49
http://pasarinko.zeroweb.kr/bbs/board.php?bo_table=notice&wr_id=10087836 http://pasarinko.zeroweb.kr/bbs/board.php?bo_table=notice&wr_id=10087836: Uncover Singapore'ѕ leading deals ɑt Kaizenaire.ϲo... 05/24 19:51
https://4bedroomvillaforsaleindubai.org https://4bedroomvillaforsaleindubai.org: We Advise You Let out Apartments In Dubai With all... 05/24 18:56
https://xn--d1arpf.xn--p1ai/community/profile/tiaraahotels/ https://xn--d1arpf.xn--p1ai/community/profile/tiaraahotels/: Very well written article. 05/24 18:55
https://www.thegameroom.org/backgammon-spelregels/ https://www.thegameroom.org/backgammon-spelregels/: Контент для взрослых доступен через надежные и про... 05/24 18:48
https://www.imprentaconcepcion.cl/2026/05/23/vegasino-promo-code-offers-big-wins-now/ https://www.imprentaconcepcion.cl/2026/05/23/vegasino-promo-code-offers-big-wins-now/: Thanks for the post. 05/24 18:17
Services from s21g
YOMU Web小説リーダー
小説投稿サイトの公式ページを開き、WebView表示と読み上げ向け表示を切り替えて、移動中や作業中にもWeb小説の続きを聴きやすくするiPhoneアプリです。
補助探
公開されている補助金・助成金情報を集約し、条件に合う制度を探しやすくするサービスです。
jotter.me
個人開発者のためのホスティング一体型ノートサービス
ハンドミラー
iPhone向けの手鏡アプリ
ツイプロ(twpro)
Twitterプロフィールの高速検索エンジン