5

I'd like to optimize my Rails 3.2.13 application that's currently using postgis through activerecord-postgis-adapter gem.

The problem is that when I make a query in a table, even if there are only regular fields in it (no geography/geometry/this kind of stuff), this query is preceded by another query on postgis "geometry_columns" table.

Example:

(5.6ms)  SELECT * FROM geometry_columns WHERE f_table_name='srlzd_infos'
  SrlzdInfo Load (1.1ms)  SELECT "srlzd_infos".* FROM "srlzd_infos" WHERE "srlzd_infos"."user_id" = 1009 LIMIT 1

But I use postgis only in my Users table/model.

Does anyone know how can I avoid those unnecessary queries?

Thank you all.

4

1 回答 1

1

我相信这回答了你的问题:https ://github.com/rgeo/rgeo/issues/29 。从问题:

activerecord 适配器发出这些选择以确定数据库的结构。他们不是没用的。在您上面提到的选择的情况下,正是要确定该表是否包含任何地理空间列(如果是,它们是哪些列以及它们是如何配置的)。如果您使用的是 postgis 适配器,那么您可能还会注意到对 pg_attribute 的选择,可能还有其他一些。它们都是 activerecord 发挥其魔力的一部分。

好消息是,我相信 activerecord 会缓存它在非开发环境中收集的所有结构信息,因此您应该在每个表、每个 rails 进程中只看到这些选择一次。它们应该是无害的,即使对于没有空间列的表也是如此。

于 2014-06-11T18:38:49.437 回答