Sails.js js blueprint route和本机SQL查询之间存在巨大的性能差异

Sails.js js blueprint route和本机SQL查询之间存在巨大的性能差异,sails.js,waterline,sails-postgresql,Sails.js,Waterline,Sails Postgresql,我正在为一个特定的项目使用sails版本0.10.5。我们使用postgresql作为基础数据库,它的大小只有几GB。最近我开始注意到一个问题。有一个postgres表,其模型定义如下: module.exports = { attributes: { user: { model: "user", required: true }, organization: { model: "organization", re

我正在为一个特定的项目使用sails版本0.10.5。我们使用postgresql作为基础数据库,它的大小只有几GB。最近我开始注意到一个问题。有一个postgres表,其模型定义如下:

module.exports = {

  attributes: {

    user: {
      model: "user",
      required: true
    },

    organization: {
      model: "organization",
      required: true
    },

    questionaire: {
      model: "questionaire",
      required: true
    },

    mailinglist: {
      model: "mailinglist",
      defaultsTo: null
    },

    name: {
      type: "string",
      required: true
    },

    broadcast: {
      type: "boolean",
      defaultsTo: false
    },

    link: {
      type: "string",
      defaultsTo: null
    },

    count: {
      type: "integer",
      defaultsTo: 0
    }


  }
};
当我使用控制器的蓝图路由时,URL如下:

GET/api/survey?广播=false,组织=2

返回结果花了30多秒。我在postgres中索引了这两列,还有一个使用这两列的复合索引。另外,当我在postgres中运行查询时,它以毫秒为单位返回结果。所以,我很困惑,为什么通过蓝图路线要花这么长时间

因此,我通过在控制器中重写来修改路由:

  find: function (req, res){
    var packet = req.params.all();
    var myQuery = "select * from survey where 1=1 ";
    Object.keys(packet).forEach(function (key){
      myQuery += " and "+ key + " = " + packet[key] + " "
    })
    Survey.query(myQuery, function (err, result){
      if(err){
        return res.json(500, err);
      }
      else{
        return res.json(200, result.rows)        
      }
    })
  },

这样我就能获得极快的表现。所以我的问题是,当性能是一项要求时,我是否应该避免使用Waterline的方法,或者在我的模型定义或其他地方是否有任何错误?

是否禁用blueprint的“填充”选项?如果你不是每个协会的会员,也许就是因为这个你的表现不好?选中/config/blueprints.js以禁用填充选项Perfect!我在船帆控制台上试过。有填充和无填充之间存在显著差异我希望解决方案有所帮助。如果您需要其他资源,这里有一个用于sails.js、node.js和吃水线问题的聊天室。虽然这个解决方案有帮助,但它让我非常担心是否使用关联?如果我在postgres中的索引已经优化,为什么性能会滞后?通过在原生SQL查询中连接所有这些表,我可以非常高效地获取数据