dsdb-descriptor: Do not do a subtree search unless we have child entries
authorAndrew Bartlett <abartlet@samba.org>
Sun, 23 Jun 2013 09:47:35 +0000 (19:47 +1000)
committerStefan Metzmacher <metze@samba.org>
Wed, 24 Jul 2013 14:34:58 +0000 (16:34 +0200)
This avoids a subtree search here in most cases where an object is deleted.

Andrew Bartlett

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source4/dsdb/samdb/ldb_modules/descriptor.c

index 7743baaaa5b8c94eb83a8dd2528d5060c99481b0..ceac8db7de290f54cdeceb3cc2e191299fe37922 100644 (file)
@@ -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,