3
ªôÁg³  ã               @   s   G d d„ dƒZ dS )c               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚMigrationOptimizera]  
    Power the optimization process, where you provide a list of Operations
    and you are returned a list of equal or shorter length - operations
    are merged into one if possible.

    For example, a CreateModel and an AddField can be optimized into a
    new CreateModel, and CreateModel and DeleteModel can be optimized into
    nothing.
    c             C   sJ   |dkrt dƒ‚d| _x.| j||ƒ}|  jd7  _||kr>|S |}qW dS )a…  
        Main optimization entry point. Pass in a list of Operation instances,
        get out a new list of Operation instances.

        Unfortunately, due to the scope of the optimization (two combinable
        operations might be separated by several hundred others), this can't be
        done as a peephole optimization with checks/output implemented on
        the Operations themselves; instead, the optimizer looks at each
        individual operation and scans forwards in the list to see if there
        are any matches, stopping at boundaries - operations which can't
        be optimized over (RunSQL, operations on the same field/model, etc.)

        The inner loop is run until the starting list is the same as the result
        list, and then the result is returned. This means that operation
        optimization must be stable and always return an equal or shorter list.
        Nzapp_label must be a str.é    é   )Ú	TypeErrorZ_iterationsÚoptimize_inner)ÚselfÚ
operationsÚ	app_labelÚresult© r
   ú\/var/www/tester-filtro-web/env/lib/python3.6/site-packages/django/db/migrations/optimizer.pyÚoptimize   s    zMigrationOptimizer.optimizec       
         sö   g }xìt |ƒD ]à\}}d}xÒt ||d d… ƒD ]°\}‰|jˆˆ ƒ}t|tƒrØ||d || d … }	|r€|j|	ƒ |j|ƒ n:t‡ ‡fdd„|	D ƒƒr®|j|ƒ |j|	ƒ n|j|ƒ P |j||| d d… ƒ |S |s0d}q0W |j|ƒ qW |S )zInner optimization loop.Tr   Nc             3   s   | ]}|j ˆˆ ƒd kV  qdS )TN)Úreduce)Ú.0Úop)r   Úotherr
   r   ú	<genexpr>5   s    z4MigrationOptimizer.optimize_inner.<locals>.<genexpr>é   F)Ú	enumerater   Ú
isinstanceÚlistÚextendÚallÚappend)
r   r   r   Znew_operationsÚiZ	operationÚrightÚjr	   Z
in_betweenr
   )r   r   r   r   (   s*    



z!MigrationOptimizer.optimize_innerN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r
   r
   r
   r   r      s   	r   N)r   r
   r
   r
   r   Ú<module>   s    