Caching only a relation data from FuelPHP ORM result

I'm developing app with FuelPHP & mySql and I'm using the provided ORM functionality. The problem is with following tables:

Table: pdm_data

  • Massive table (350+ columns, many rows)
  • Table data is rather static (updates only once a day)
  • Primary key: obj_id
  • Table: change_request

  • Only few columns
  • Data changes often (10-20 times / min)
  • References primary key (obj_id from table pdm_data)
  • Users can customize datasheet that is visible to them, eg. they can save filters (eg. change_request.obj_id=34 AND pdm_data.state = 6) on columns which then are translated to query realtime with ORM.

    However, the querying with ORM is really slow as the table pdm_data is large and even ~100 rows will result in many mbs of data. The largest problem seems to be in FuelPHP ORM: even if the query itself is relatively fast model hydration etc. takes many seconds. Ideal solution would be to cache results from pdm_data table as it is rather static. However, as far as I know FuelPHP doesn't let you cache tables through relations (you can cache the complete result of query, thus both tables or none).

    Furthermore, using normal SQL query with join instead of ORM is not ideal solution, as I need to handle other tasks where hydrated models are awesome.

    I have currently following code:

     //Initialize the query and use eager-loading
     $query = Model_Changerequest::query()->related('pdmdata');
    
    
    foreach($filters as $filter)
    {
     //First parameter can point to either table
     $query->where($filter[0], $filter[1], $filter[2]);
    }
    
    $result = $query->get();
    

    ...

    Does someone have a good solution for this?

    Thanks for reading!


    The slowness of the version 1 ORM is a known problem which is being addressed with v2. My current benchmarks are showing that v1 orm takes 2.5 seconds (on my machine, ymmv) to hydrate 40k rows while the current v2 alpha takes around 800ms.

    For now I am afraid that the easiest solution is to do away with the ORM for large selects and construct the queries using the DB class. I know you said that you want to keep the abstraction of the ORM to ease development, one solution is to use as_object('MyModel') to return populated model objects.

    On the other hand if performance is your main concern then the ORM is simply not suitable.

    链接地址: http://www.djcxy.com/p/64812.html

    上一篇: 当添加到模型属性时,Fuelphp ORM意外的结果

    下一篇: 只缓存来自FuelPHP ORM结果的关系数据