Atlantis-Software / sails-hook-orm-offshore

Implements support for Offshore ORM in Sails.
https://github.com/Atlantis-Software/Offshore
8 stars 1 forks source link

offshore not populating if I don't .limit() results #5

Closed japel closed 8 years ago

japel commented 8 years ago

Hey there!

I am using sails-hook-orm-offshore with sails 0.12.4 and I have 2 models:

ModelA containing ~2000 records and ModelB containing ~80000 I'm associating ModelA with ModelB with a one-to-many association via an ID field. When I:

ModelA
    .find()
    .populate("data")
    .exec(function (error, found) {
      if (error) {
        console.error(error);
      }

      for (var i = 0; i < found.length; i++) {
        if (found[i].data.length>0) {
          console.log(util.inspect(found[i], {depth: 10}));
        }
      }
    });

nothing is logged to console, but if I:

ModelA
    .find()
    .limit(30)
    .populate("data")
    .exec(function (error, found) {
      if (error) {
        console.error(error);
      }

      for (var i = 0; i < found.length; i++) {
        if (found[i].data.length>0) {
          console.log(util.inspect(found[i], {depth: 10}));
        }
      }
    });

records are logged... The limitation seems to work until weird 1005 records, so if I .limit(1006) it again stops populating, and nothing gets logged.

What could be happening here?

atiertant commented 8 years ago

hi japel, i think your adapter doesn't answer... which one do you use? or this could be the database performance problem...

japel commented 8 years ago

I am using sails-mysql... I will check the server logs and see if anything points to performance

japel commented 8 years ago

It was a performance issue... Thanks for pointing me into that direction. I'll close this.

atiertant commented 8 years ago

sails-mysql use union for populate, you could try using offshore-sql who use left join ... i would be curious to see performance diff

japel commented 8 years ago

populate_offshore-sql: 55265ms populate_sails-mysql: 3339517ms

:flushed:

atiertant commented 8 years ago

@japel offshore-sql would be 60x faster than sails-mysql in this case ! Amazing !

japel commented 8 years ago

yeah, crazy!

atiertant commented 8 years ago

@japel which query did you used for your test ? did you used skip or limit on populate ?

japel commented 8 years ago

@atiertant no, no skip and no limit

atiertant commented 8 years ago

thanks for your tests