From 03b44d26fd17761675fe33ab29e8f325f59d8a5c Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sun, 23 Jun 2013 19:47:35 +1000 Subject: dsdb-descriptor: Do not do a subtree search unless we have child entries This avoids a subtree search here in most cases where an object is deleted. Andrew Bartlett Signed-off-by: Andrew Bartlett Reviewed-by: Stefan Metzmacher --- source4/dsdb/samdb/ldb_modules/descriptor.c | 33 ++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'source4/dsdb') diff --git a/source4/dsdb/samdb/ldb_modules/descriptor.c b/source4/dsdb/samdb/ldb_modules/descriptor.c index 7743baaaa5..ceac8db7de 100644 --- a/source4/dsdb/samdb/ldb_modules/descriptor.c +++ b/source4/dsdb/samdb/ldb_modules/descriptor.c @@ -1186,8 +1186,39 @@ static int descriptor_sd_propagation_recursive(struct ldb_module *module, const char * const no_attrs[] = { "@__NONE__", NULL }; struct descriptor_changes *c; struct descriptor_changes *stopped_stack = NULL; + enum ldb_scope scope; int ret; + /* + * First confirm this object has children, or exists (depending on change->force_self) + * + * LDB_SCOPE_SUBTREE searches are expensive. + * + * Note: that we do not search for deleted/recycled objects + */ + ret = dsdb_module_search(module, + change, + &res, + change->dn, + LDB_SCOPE_ONELEVEL, + no_attrs, + DSDB_FLAG_NEXT_MODULE | + DSDB_FLAG_AS_SYSTEM, + NULL, /* parent_req */ + "(objectClass=*)"); + if (ret != LDB_SUCCESS) { + return ret; + } + + if (res->count == 0 && !change->force_self) { + TALLOC_FREE(res); + return LDB_SUCCESS; + } else if (res->count == 0 && change->force_self) { + scope = LDB_SCOPE_BASE; + } else { + scope = LDB_SCOPE_SUBTREE; + } + /* * Note: that we do not search for deleted/recycled objects */ @@ -1195,7 +1226,7 @@ static int descriptor_sd_propagation_recursive(struct ldb_module *module, change, &res, change->dn, - LDB_SCOPE_SUBTREE, + scope, no_attrs, DSDB_FLAG_NEXT_MODULE | DSDB_FLAG_AS_SYSTEM, -- cgit