我正在使用 Symfony2、Doctrine 和 ACL,但遇到了性能问题。
在 Twig 模板中,我需要检查集合中每个公司的当前用户角色以显示链接:
{%- if is_expr_granted("hasRole('ROLE_SUPPORT') or hasPermission(object, 'OPERATOR')", company) -%}
<a href="configure">{{- company.name -}}</a>
{%- else -%}
我可以在 webProfiler 中看到为每个公司生成了以下 2 个查询:
SELECT a.ancestor_id
FROM acl_object_identities o
INNER JOIN acl_classes c ON c.id = o.class_id INNER JOIN acl_object_identity_ancestors a ON a.object_identity_id = o.id
WHERE ((o.object_identifier = '154' AND c.class_type = 'St\\CoreBundle\\Entity\\Company'))`
和
SELECT o.id as acl_id, o.object_identifier, o.parent_object_identity_id, o.entries_inheriting, c.class_type, e.id as ace_id, e.object_identity_id, e.field_name, e.ace_order, e.mask, e.granting, e.granting_strategy, e.audit_success, e.audit_failure, s.username, s.identifier as security_identifier
FROM acl_object_identities o
INNER JOIN acl_classes c ON c.id = o.class_id
LEFT JOIN acl_entries e
ON ( e.class_id = o.class_id AND (e.object_identity_id = o.id OR e.object_identity_id IS NULL) )
LEFT JOIN acl_security_identities s ON ( s.id = e.security_identity_id )
WHERE (o.id =2189)
如何避免循环查询?