Uploaded image for project: 'Blesta Core'
  1. Blesta Core
  2. CORE-4186

Improve Invoices::getNextInvoiceVars() id_value sub-queries

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      We can make the following change to Invoices::getNextInvoiceVars() to improve performance without creating a new index

              $values = [$inv_start, $inv_increment,
                  $inv_start];
      
              $sub_query->select(['IFNULL(GREATEST(MAX(t1.id_value),?)+?,?)'], false)->
                  appendValues($values)->
                  from(['invoices' => 't1'])->
                  innerJoin('clients', 'clients.id', '=', 't1.client_id', false)->
                  innerJoin('client_groups', 'client_groups.id', '=', 'clients.client_group_id', false)->
                  where('client_groups.company_id', '=', Configure::get('Blesta.company_id'))->
                  where('t1.id_format', '=', $vars['id_format']);
      

      To

              $values = [$inv_start, $inv_increment];
      
              $sub_query->select(['IFNULL(t1.id_value, ?) + ?'], false)->
                  appendValues($values)->
                  from(['invoices' => 't1'])->
                  innerJoin('clients', 'clients.id', '=', 't1.client_id', false)->
                  innerJoin('client_groups', 'client_groups.id', '=', 'clients.client_group_id', false)->
                  where('client_groups.company_id', '=', Configure::get('Blesta.company_id'))->
                  where('t1.id_format', '=', $vars['id_format'])->
                  order(['t1.id_value' => 'DESC'])->
                  limit(1);
      

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Unassigned
            Reporter:
            jonathan Jonathan Reissmueller
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: