Lançado Adianti Framework 7.6!
Clique aqui para saber mais
demora ao carregar dados. Olá, estou com problemas com as listagens no template II do adianti, estão demorando muito para carregar algumas paginas, (duas paginas, uma contem mais de 3 mil linhas na tabela, a outra não tentos dados assim, mas o select é mais criterioso) as vezes nem carrega a pagina (esgota o tempo). Como resolver esse problema? Meu pc é um notebook core i5 com 4gb de memoria RAM...
BI
demora ao carregar dados.  
Fechado
Olá, estou com problemas com as listagens no template II do adianti, estão demorando muito para carregar algumas paginas, (duas paginas, uma contem mais de 3 mil linhas na tabela, a outra não tentos dados assim, mas o select é mais criterioso) as vezes nem carrega a pagina (esgota o tempo).

Como resolver esse problema?

Meu pc é um notebook core i5 com 4gb de memoria RAM

Curso completo Meu Negócio Pronto
Use para si, ou transforme em um negócio: Inclui aulas e códigos-fontes
Gestor de conteúdo (SITE) + Loja Virtual (E-Commerce) + Emissor de Notas para infoprodutos


Meu negócio pronto Quero me inscrever agora!

Comentários (4)


JC

Saudações, já leu este artigo www.adianti.com.br/forum/pt/view_879?relatorios-com-queries-complexa, ou postar o codigo para apreciação.
BI

Opa, segue o código de uma pagina de listagem...

  1. <?php 
  2. class Evento_aplicacaoList extends TPage
  3. {
  4.     private $form;     // registration form
  5.     private $datagrid// listing
  6.     private $pageNavigation;
  7.     private $loaded;
  8.     
  9.     /**
  10.      * Class constructor
  11.      * Creates the page, the form and the listing
  12.      */
  13.     public function __construct()
  14.     {
  15.         parent::__construct();
  16.         
  17.         // creates the form
  18.         $this->form = new TForm('form_search_Evento_aplicacao');
  19.         $this->form->class 'tform'// CSS class
  20.         
  21.         // creates a table
  22.         $table = new TTable;
  23.         $table-> width '100%';
  24.         $this->form->add($table);
  25.         
  26.         // add a row for the form title
  27.         $row $table->addRow();
  28.         $row->class 'tformtitle'// CSS class
  29.         $row->addCell( new TLabel('Evento_aplicacao') )->colspan 6;
  30.         
  31.         // create the form fields
  32.         $evento                         = new TEntry('evento');
  33.         $empreendimento_id              = new TDBCombo('empreendimento_id','sqlserver','Empreendimento','id','sigla');
  34.         $aplicacao_id                   = new TCombo('aplicacao_id');
  35.         $evento                         = new TEntry('evento');
  36.         $grupo_id                       = new TDBCombo('grupo_id''sqlserver','Grupo','id','descricao');
  37.         
  38.         // set change action for empreendimento
  39.         $change_action = new TAction(array($this'onChange'));
  40.         $empreendimento_id->setChangeAction($change_action);
  41.         // define the sizes
  42.         $evento->setSize(625);
  43.         $grupo_id->setSize(200);
  44.         $aplicacao_id->setSize(100);
  45.         $empreendimento_id->setSize(100);
  46.         // add one row for each form field
  47.         $row $table->addRow();
  48.         $row->addCell($label_empreendimento_id = new TLabel('Empreendimento:'));
  49.         $row->addCell($empreendimento_id);
  50.         $row->addCell($label_aplicacao_id = new TLabel('Aplicação:'));
  51.         $row->addCell($aplicacao_id);
  52.         $row->addCell($label_grupo_id = new TLabel('Grupo:'));
  53.         $row->addCell($grupo_id);
  54.         $row $table->addRow();
  55.         $row->addCell($label_evento = new TLabel('Evento:'));
  56.         $row->addCell($evento)->colspan 6;
  57.         
  58.         $this->form->setFields(array($evento,$grupo_id,$aplicacao_id,$empreendimento_id));
  59.         // keep the form filled during navigation with session data
  60.         $this->form->setDataTSession::getValue('Evento_aplicacao_filter_data') );
  61.         
  62.         // create two action buttons to the form
  63.         $find_button TButton::create('find', array($this'onSearch'), _t('Find'), 'ico_find.png');
  64.         $new_button  TButton::create('new',  array('Evento_aplicacaoForm''onEdit'), _t('New'), 'ico_new.png');
  65.         
  66.         $this->form->addField($find_button);
  67.         $this->form->addField($new_button);
  68.         
  69.         $buttons_box = new THBox;
  70.         $buttons_box->add($find_button);
  71.         $buttons_box->add($new_button);
  72.         
  73.         // add a row for the form action
  74.         $row $table->addRow();
  75.         $row->class 'tformaction'// CSS class
  76.         $row->addCell($buttons_box)->colspan 6;
  77.         
  78.         // creates a Datagrid
  79.         $this->datagrid = new TDataGrid;
  80.         $this->datagrid->setHeight(320);
  81.         
  82.         // creates the datagrid columns
  83.         $id   = new TDataGridColumn('id''ID''center'30);
  84.         $evento   = new TDataGridColumn('evento''Evento''left'450);
  85.         $grupo_id   = new TDataGridColumn('grupos''Grupo''left'100);
  86.         $aplicacao_id   = new TDataGridColumn('aplicacaos''Aplicação''center'50);
  87.         $empreendimento_id   = new TDataGridColumn('empreendimentos''Empreendimento''center'50);
  88.         $indicador   = new TDataGridColumn('indicador''Indicador''center'50);
  89.         // add the columns to the DataGrid
  90.         $this->datagrid->addColumn($id);
  91.         $this->datagrid->addColumn($empreendimento_id);
  92.         $this->datagrid->addColumn($aplicacao_id);
  93.         $this->datagrid->addColumn($evento);
  94.         $this->datagrid->addColumn($grupo_id);
  95.         $this->datagrid->addColumn($indicador);        
  96.         
  97.         // creates the datagrid column actions
  98.         $order_id= new TAction(array($this'onReload'));
  99.         $order_id->setParameter('order''id');
  100.         $id->setAction($order_id);
  101.         $order_evento= new TAction(array($this'onReload'));
  102.         $order_evento->setParameter('order''evento');
  103.         $evento->setAction($order_evento);
  104.         $order_grupo_id= new TAction(array($this'onReload'));
  105.         $order_grupo_id->setParameter('order''grupo_id');
  106.         $grupo_id->setAction($order_grupo_id);
  107.         $order_aplicacao_id= new TAction(array($this'onReload'));
  108.         $order_aplicacao_id->setParameter('order''aplicacao_id');
  109.         $aplicacao_id->setAction($order_aplicacao_id);
  110.         $order_empreendimento_id= new TAction(array($this'onReload'));
  111.         $order_empreendimento_id->setParameter('order''empreendimento_id');
  112.         $empreendimento_id->setAction($order_empreendimento_id);
  113.         
  114.         // creates two datagrid actions
  115.         $action1 = new TDataGridAction(array('Evento_aplicacaoForm''onEdit'));
  116.         $action1->setLabel(_t('Edit'));
  117.         $action1->setImage('ico_edit.png');
  118.         $action1->setField('id');
  119.         
  120.         $action2 = new TDataGridAction(array($this'onDelete'));
  121.         $action2->setLabel(_t('Delete'));
  122.         $action2->setImage('ico_delete.png');
  123.         $action2->setField('id');
  124.         
  125.         // add the actions to the datagrid
  126.         $this->datagrid->addAction($action1);
  127.         $this->datagrid->addAction($action2);
  128.         
  129.         // create the datagrid model
  130.         $this->datagrid->createModel();
  131.         
  132.         // creates the page navigation
  133.         $this->pageNavigation = new TPageNavigation;
  134.         $this->pageNavigation->setAction(new TAction(array($this'onReload')));
  135.         $this->pageNavigation->setWidth($this->datagrid->getWidth());
  136.         
  137.         // create the page container
  138.         $table = new TTable;
  139.         $table->style 'width: 80%';
  140.         $table->addRow()->addCell(new TXMLBreadCrumb('menu.xml'__CLASS__));
  141.         $table->addRow()->addCell($this->form);
  142.         $table->addRow()->addCell($this->datagrid);
  143.         $table->addRow()->addCell($this->pageNavigation);
  144.                
  145.         parent::add($table);
  146.     }
  147.     
  148.     /**
  149.      * method onInlineEdit()
  150.      * Inline record editing
  151.      * @param $param Array containing:
  152.      *              key: object ID value
  153.      *              field name: object attribute to be updated
  154.      *              value: new attribute content 
  155.      */
  156.     function onInlineEdit($param)
  157.     {
  158.         try
  159.         {
  160.             // get the parameter $key
  161.             $field $param['field'];
  162.             $key   $param['key'];
  163.             $value $param['value'];
  164.             
  165.             TTransaction::open('sqlserver'); // open a transaction with database
  166.             $object = new Evento_aplicacao($key); // instantiates the Active Record
  167.             $object->{$field} = $value;
  168.             $object->store(); // update the object in the database
  169.             TTransaction::close(); // close the transaction
  170.             
  171.             $this->onReload($param); // reload the listing
  172.             new TMessage('info'"Record Updated");
  173.         }
  174.         catch (Exception $e// in case of exception
  175.         {
  176.             new TMessage('error''<b>Error</b> ' $e->getMessage()); // shows the exception error message
  177.             TTransaction::rollback(); // undo all pending operations
  178.         }
  179.     }
  180.     
  181.     /**
  182.      * method onSearch()
  183.      * Register the filter in the session when the user performs a search
  184.      */
  185.     function onSearch()
  186.     {
  187.         // get the search form data
  188.         $data $this->form->getData();
  189.         
  190.         // clear session filters
  191.         TSession::setValue('Evento_aplicacaoList_filter_evento',   NULL);
  192.         TSession::setValue('Evento_aplicacaoList_filter_grupo_id',   NULL);
  193.         TSession::setValue('Evento_aplicacaoList_filter_aplicacao_id',   NULL);
  194.         TSession::setValue('Evento_aplicacaoList_filter_empreendimento_id',   NULL);
  195.         if (isset($data->evento) AND ($data->evento)) {
  196.             $filter = new TFilter('evento''like'"%{$data->evento}%"); // create the filter
  197.             TSession::setValue('Evento_aplicacaoList_filter_evento',   $filter); // stores the filter in the session
  198.         }
  199.         if (isset($data->grupo_id) AND ($data->grupo_id)) {
  200.             $filter = new TFilter('grupo_id''='"$data->grupo_id"); // create the filter
  201.             TSession::setValue('Evento_aplicacaoList_filter_grupo_id',   $filter); // stores the filter in the session
  202.         }
  203.         if (isset($data->aplicacao_id) AND ($data->aplicacao_id)) {
  204.             $filter = new TFilter('aplicacao_id''='"$data->aplicacao_id"); // create the filter
  205.             TSession::setValue('Evento_aplicacaoList_filter_aplicacao_id',   $filter); // stores the filter in the session
  206.         }
  207.         if (isset($data->empreendimento_id) AND ($data->empreendimento_id)) {
  208.             $filter = new TFilter('empreendimento_id''='"$data->empreendimento_id"); // create the filter
  209.             TSession::setValue('Evento_aplicacaoList_filter_empreendimento_id',   $filter); // stores the filter in the session
  210.         }
  211.         
  212.         // fill the form with data again
  213.         $this->form->setData($data);
  214.         
  215.         // keep the search data in the session
  216.         TSession::setValue('Evento_aplicacao_filter_data'$data);
  217.         
  218.         $param=array();
  219.         $param['offset']    =0;
  220.         $param['first_page']=1;
  221.         $this->onReload($param);
  222.     }
  223.     
  224.     /**
  225.      * method onReload()
  226.      * Load the datagrid with the database objects
  227.      */
  228.     function onReload($param NULL)
  229.     {
  230.         try
  231.         {
  232.             // open a transaction with database 'sqlserver'
  233.             TTransaction::open('sqlserver');
  234.             
  235.             // creates a repository for Evento_aplicacao
  236.             $repository = new TRepository('Evento_aplicacao');
  237.             $limit 30;
  238.             // creates a criteria
  239.             $criteria = new TCriteria;
  240.             
  241.             // default order
  242.             if (empty($param['order']))
  243.             {
  244.                 $param['order'] = 'id';
  245.                 $param['direction'] = 'asc';
  246.             }
  247.             $criteria->setProperties($param); // order, offset
  248.             $criteria->setProperty('limit'$limit);
  249.             
  250.             if (TSession::getValue('Evento_aplicacaoList_filter_evento')) {
  251.                 $criteria->add(TSession::getValue('Evento_aplicacaoList_filter_evento')); // add the session filter
  252.             }
  253.             if (TSession::getValue('Evento_aplicacaoList_filter_grupo_id')) {
  254.                 $criteria->add(TSession::getValue('Evento_aplicacaoList_filter_grupo_id')); // add the session filter
  255.             }
  256.             if (TSession::getValue('Evento_aplicacaoList_filter_aplicacao_id')) {
  257.                 $criteria->add(TSession::getValue('Evento_aplicacaoList_filter_aplicacao_id')); // add the session filter
  258.             }
  259.             if (TSession::getValue('Evento_aplicacaoList_filter_empreendimento_id')) {
  260.                 $criteria->add(TSession::getValue('Evento_aplicacaoList_filter_empreendimento_id')); // add the session filter
  261.             }
  262.             
  263.             // load the objects according to criteria
  264.             $objects $repository->load($criteriaFALSE);
  265.             
  266.             $this->datagrid->clear();
  267.             if ($objects)
  268.             {
  269.                 // iterate the collection of active records
  270.                 foreach ($objects as $object)
  271.                 {
  272.                     //identifica quando é indicador ou não.
  273.                     if ($object->indicador == 1){
  274.                         $object->indicador 'Sim';
  275.                     }else{
  276.                         $object->indicador 'Não';
  277.                     }
  278.                     // add the object inside the datagrid
  279.                     $this->datagrid->addItem($object);
  280.                 }
  281.             }
  282.             
  283.             // reset the criteria for record count
  284.             $criteria->resetProperties();
  285.             $count$repository->count($criteria);
  286.             
  287.             $this->pageNavigation->setCount($count); // count of records
  288.             $this->pageNavigation->setProperties($param); // order, page
  289.             $this->pageNavigation->setLimit($limit); // limit
  290.             
  291.             // close the transaction
  292.             TTransaction::close();
  293.             $this->loaded true;
  294.         }
  295.         catch (Exception $e// in case of exception
  296.         {
  297.             // shows the exception error message
  298.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  299.             
  300.             // undo all pending operations
  301.             TTransaction::rollback();
  302.         }
  303.     }
  304.     
  305.     /**
  306.      * method onDelete()
  307.      * executed whenever the user clicks at the delete button
  308.      * Ask if the user really wants to delete the record
  309.      */
  310.     function onDelete($param)
  311.     {
  312.         // define the delete action
  313.         $action = new TAction(array($this'Delete'));
  314.         $action->setParameters($param); // pass the key parameter ahead
  315.         
  316.         // shows a dialog to the user
  317.         new TQuestion(TAdiantiCoreTranslator::translate('Do you really want to delete ?'), $action);
  318.     }
  319.     
  320.     /**
  321.      * method Delete()
  322.      * Delete a record
  323.      */
  324.     function Delete($param)
  325.     {
  326.         try
  327.         {
  328.             $key=$param['key']; // get the parameter $key
  329.             TTransaction::open('sqlserver'); // open a transaction with database
  330.             $object = new Evento_aplicacao($keyFALSE); // instantiates the Active Record
  331.             $object->delete(); // deletes the object from the database
  332.             TTransaction::close(); // close the transaction
  333.             $this->onReload$param ); // reload the listing
  334.             new TMessage('info'TAdiantiCoreTranslator::translate('Record deleted')); // success message
  335.         }
  336.         catch (Exception $e// in case of exception
  337.         {
  338.             new TMessage('error''<b>Error</b> ' $e->getMessage()); // shows the exception error message
  339.             TTransaction::rollback(); // undo all pending operations
  340.         }
  341.     }
  342.     
  343.     /**
  344.      * method show()
  345.      * Shows the page
  346.      */
  347.     function show()
  348.     {
  349.         // check if the datagrid is already loaded
  350.         if (!$this->loaded AND (!isset($_GET['method']) OR $_GET['method'] !== 'onReload') )
  351.         {
  352.             $this->onReloadfunc_get_arg(0) );
  353.         }
  354.         parent::show();
  355.     }
  356.     
  357.     //função para carregar as aplicações 'equipamentos'
  358.     public static function onChange($param)
  359.     {
  360.         TTransaction::open('sqlserver');
  361.         $criteria = new TCriteria;
  362.         $criteria->add(new TFilter('empreendimento_id''='$param['empreendimento_id']));
  363.         
  364.         $repository = new TRepository('Aplicacao');
  365.         $aplicacaos $repository->load($criteria);
  366.         
  367.         $options = array();
  368.         foreach ($aplicacaos as $aplicacao){
  369.             $options[$aplicacao->id] = $aplicacao->sigla;
  370.         }
  371.         
  372.         //TForm::sendData('form_Vertedouro', $objeto);            
  373.         TCombo::reload('form_search_Evento_aplicacao''aplicacao_id'$options);
  374.         
  375.     }
  376. }
  377. ?>
PD

Não creio que o problema tenha alguma relação com o framework.
A tabela é muito pequena e o select é paginado. Temos cases com milhões de registros.
Acredito que é um problema relativo ao ambiente. Precisamos de mais informações sobre
seu ambiente para ajudar. Aparentemente seu código não tem problemas.
BI

Obrigado pela atenção!
Resolvido o problema, em tabelas onde tem muitas chaves estrangeiras e a classe model carrega os objetos referenciados, a listagem fica lenta.

Então segui as recomendações do próprio Pablo em um artigo publicado... Criei views somente para as listagens, fica extremamente rápido para carregar a página.