以下标准的运行速度令人无法接受。如果没有在表的主键或索引上输入太多细节,您是否看到任何可以使其运行更快的特定内容?
def results = OpportunityApplication.createCriteria().list() {
isNull('dateDeleted')
or {
opportunityInst {
isNull('dateDeleted')
opportunity {
isNull('dateDeleted')
gt('advertisingEndDate', new Date())
eq('useOrgAsContact', false)
}
opportunityLocation {
isNull('dateDeleted')
eq("email", user.email)
}
}
if (isPartner)
{
opportunityInst {
isNull('dateDeleted')
opportunity {
isNull('dateDeleted')
gt('advertisingEndDate', new Date())
eq('useOrgAsContact', true)
organisation {
isNull('dateDeleted')
eq("email", user.email)
}
}
}
}
}
}
答案 0 :(得分:0)
根据我的标准进行优化非常简单。我所要做的就是将重复的位移动到共享片段中,如下所示
opportunityInst {
isNull('dateDeleted')
opportunity {
isNull('dateDeleted')
gt('advertisingEndDate', new Date())
}
or {
if (isPartner)
{
opportunity {
eq('useOrgAsContact', true)
organisation {
isNull('dateDeleted')
eq("email", user.email)
}
}
}
and {
opportunity {
eq('useOrgAsContact', false)
}
opportunityLocation {
isNull('dateDeleted')
eq("email", user.email)
}
}
}
}