[Cubicweb] Integrating CubicWeb views into Pyramid (long)

Nicolas Chauvat nicolas.chauvat at logilab.fr
Wed Aug 6 11:22:27 CEST 2014


On Wed, Aug 06, 2014 at 12:51:48AM +0200, Christophe de Vienne wrote:
> AppObjectA
>     __select__ = is_instance('Event')
> 
> AppObjectB
>     __select__ = is_instance('Event') & match_user_groups('managers')
> 
> AppObjectC
>     __select__ = is_instance("Event") &
> match_user_groups('managers') | is_instance("SmallEvent") &
> match_user_groups("users")

I can see a table here:

------------------------------ --- --- --- ----
                                A   B   C   C'
------------------------------ --- --- --- ----
is_instance('Event')            X   X   X
is_instance('SmallEvent')                   X
match_user_groups('managers')       X   X
match_user_groups('users')                  X
------------------------------ --- --- --- ----

That table describes a search problem: what is the column that returns
the highest score, knowing that (1) each row can return a "NoMatch"
or a score (2) the score of a column is the maximum of the score of
its rows.

In order to optimize things, one could use a predicate evaluation plan in
the same way a database is drafting a query evaluation plan.

Ideally, each predicate/row would be evaluated only once and we could
estimate the cost of the evaluation of each predicate as well as order
the columns by their expected score/weight.

Assuming B > C,C' > A and is_instance() costs less than
match_users_groups(), that would give the following plan::

  is_event = is_instance('Event')
  if is_event:
      if match_users_groups('managers'):
          return B
  if is_instance('SmallEvent'):
      if match_users_groups('users'):
          return C'
  if is_event:
      return A   
  return 'NoMatch'

IIRC, the current code computes the score of all the columns, then
sorts the resulting list and picks the first item. I have not the time
now to compare that with the above.

Not sure this discussion is a priority, but couldn't help contributing
to the thread :p

-- 
Nicolas Chauvat

logilab.fr - services en informatique scientifique et gestion de connaissances  



More information about the Cubicweb mailing list