Browse Source

Provide more opportunities for caching the results of model name resolution

Yentl Van Tendeloo 8 years ago
parent
commit
bb2a79d396
2 changed files with 61 additions and 77 deletions
  1. 26 26
      bootstrap/99_core.mvc
  2. 35 51
      bootstrap/core_algorithm.alc

+ 26 - 26
bootstrap/99_core.mvc

@@ -27,43 +27,43 @@ CF core {
             permissions = "221"
 
             Model SimpleClassDiagrams {
-                name = "SimpleClassDiagrams"
+                name = "formalisms/SimpleClassDiagrams"
                 location = "models/SimpleClassDiagrams/model"
                 permissions = "221"
             }
 
             Model TypeMapping {
-                name = "TypeMapping"
+                name = "formalisms/TypeMapping"
                 location = "models/TypeMapping/model"
                 permissions = "221"
             }
 
             Model Tracability {
-                name = "Tracability"
+                name = "formalisms/Tracability"
                 location = "models/Tracability/model"
                 permissions = "221"
             }
 
             Model ProcessModel {
-                name = "ProcessModel"
+                name = "formalisms/ProcessModel"
                 location = "models/ProcessModel/model"
                 permissions = "221"
             }
 
             Model ActionLanguage {
-                name = "ActionLanguage"
+                name = "formalisms/ActionLanguage"
                 location = "models/ActionLanguage/model"
                 permissions = "221"
             }
 
             Model ManualOperation {
-                name = "ManualOperation"
+                name = "formalisms/ManualOperation"
                 location = "models/ManualOperation/model"
                 permissions = "221"
             }
 
             Model Bottom {
-                name = "Bottom"
+                name = "formalisms/Bottom"
                 location = "models/Bottom/model"
                 permissions = "221"
             }
@@ -74,7 +74,7 @@ CF core {
             permissions = "221"
 
             ActionLanguage conformance_mv {
-                name = "conformance_mv"
+                name = "models/conformance_mv"
                 location = "models/Conformance_MV/model"
                 permissions = "221"
             }
@@ -86,47 +86,47 @@ CF core {
             permissions = "221"
 
             Folder tm_formalisms {
-                name = "formalisms"
+                name = "type mappings/formalisms"
                 permissions = "110"
 
                 TypeMapping TM_SimpleClassDiagrams {
-                    name = "SimpleClassDiagrams"
+                    name = "type mappings/formalisms/SimpleClassDiagrams"
                     location = "models/SimpleClassDiagrams/type_mapping"
                     permissions = "221"
                 }
 
                 TypeMapping TM_TypeMapping {
-                    name = "TypeMapping"
+                    name = "type mappings/formalisms/TypeMapping"
                     location = "models/TypeMapping/type_mapping"
                     permissions = "221"
                 }
 
                 TypeMapping TM_Tracability{
-                    name = "Tracability"
+                    name = "type mappings/formalisms/Tracability"
                     location = "models/Tracability/type_mapping"
                     permissions = "221"
                 }
 
                 TypeMapping TM_ProcessModel {
-                    name = "ProcessModel"
+                    name = "type mappings/formalisms/ProcessModel"
                     location = "models/ProcessModel/type_mapping"
                     permissions = "221"
                 }
 
                 TypeMapping TM_ActionLanguage {
-                    name = "ActionLanguage"
+                    name = "type mappings/formalisms/ActionLanguage"
                     location = "models/ActionLanguage/type_mapping"
                     permissions = "221"
                 }
 
                 TypeMapping TM_ManualOperation {
-                    name = "ManualOperation"
+                    name = "type mappings/formalisms/ManualOperation"
                     location = "models/ManualOperation/type_mapping"
                     permissions = "221"
                 }
 
                 TypeMapping TM_Bottom {
-                    name = "Bottom"
+                    name = "type mappings/formalisms/Bottom"
                     location = "models/Bottom/type_mapping"
                     permissions = "221"
                 }
@@ -134,39 +134,39 @@ CF core {
             }
 
             Folder tm_models {
-                name = "models"
+                name = "type mappings/models"
                 permissions = "110"
 
                 TypeMapping TM_conformance_mv {
-                    name = "conformance_mv"
+                    name = "type mappings/models/conformance_mv"
                     location = "models/Conformance_MV/type_mapping"
                     permissions = "221"
                 }
             }
 
             Folder tm_administration {
-                name = "administration"
+                name = "type mappings/administration"
                 permissions = "100"
 
                 TypeMapping TM_Core {
-                    name = "core"
+                    name = "type mappings/administration/core"
                     location = "models/core/type_mapping"
                     permissions = "220"
                 }
 
                 TypeMapping TM_CoreFormalism {
-                    name = "CoreFormalism"
+                    name = "type mappings/administration/CoreFormalism"
                     location = "models/CoreFormalism/type_mapping"
                     permissions = "221"
                 }
             }
 
             Folder tm_users {
-                name = "users"
+                name = "type mapping/users"
                 permissions = "110"
 
                 Folder tm_users_admin {
-                    name = "admin"
+                    name = "type mapping/users/admin"
                     permissions = "100"
                 }
             }
@@ -177,7 +177,7 @@ CF core {
             permissions = "221"
 
             Folder users_admin {
-                name = "admin"
+                name = "users/admin"
                 permissions = "200"
             }
         }
@@ -187,13 +187,13 @@ CF core {
             permissions = "110"
 
             Model CoreFormalism {
-                name = "CoreFormalism"
+                name = "administration/CoreFormalism"
                 location = "models/CoreFormalism/model"
                 permissions = "221"
             }
 
             Model Core {
-                name = "core"
+                name = "administration/core"
                 location = "models/core/model"
                 permissions = "220"
             }

+ 35 - 51
bootstrap/core_algorithm.alc

@@ -13,7 +13,6 @@ include "utils.alh"
 include "conformance_finding.alh"
 include "typing.alh"
 
-
 String core_model_location = "models/core"
 
 Element core = ?
@@ -40,26 +39,7 @@ String function get_filename(name : String):
 	return list_pop_final(string_split(name, "/"))!
 
 String function full_name(model_id : String):
-	//if (dict_in(caches["full_name"], model_id)):
-	//	if (get_entry_id(caches["full_name"][model_id]) == model_id):
-	//		return caches["full_name"]!
-
-	// No cache, or out of date
-	Element incoming
-	String parent
-	String parent_name
-
-	incoming = allAssociationOrigins(core, model_id, "contains")
-	if (set_len(incoming) > 0):
-		parent = set_pop(incoming)
-		parent_name = full_name(parent)
-		//dict_add(caches["full_name"], parent, parent_name)
-		if (parent_name == ""):
-			return read_attribute(core, model_id, "name")!
-		else:
-			return string_join(parent_name + "/", read_attribute(core, model_id, "name"))!
-	else:
-		return ""!
+	return read_attribute(core, model_id, "name")!
 
 Void function initialize_core():
 	// TODO make this more flexible by putting it in the bootstrap in a similar way as other models
@@ -274,30 +254,31 @@ String function get_entry_id(name : String):
 	String elem
 	Boolean found
 
-	i = 0
-	//log("Searching for " + name)
-	hierarchy_split = string_split(name, "/")
-	current = caches["root"]
-
-	Element dict
-	while (i < list_len(hierarchy_split)):
-		current_part = list_read(hierarchy_split, i)
-		if (current_part != ""):
-			dict = dict_create()
-			found = False
-			elems = allAssociationDestinations(core, current, "contains")
-			while (set_len(elems) > 0):
-				elem = set_pop(elems)
-				if (value_eq(read_attribute(core, elem, "name"), current_part)):
-					current = elem
-					found = True
-					break!
+	log("Searching for " + name)
+	if (name == ""):
+		return caches["root"]!
 
-			if (bool_not(found)):
-				return ""!
-		i = i + 1
+	//if (dict_in(caches["models"], name)):
+	//	if (full_name(caches["models"][name]) == name):
+	//		return caches["models"][name]!
 
-	return current!
+	current = get_entry_id(get_foldername(name))
+	if (current == ""):
+		return ""!
+
+	log("Got result!")
+	if (current_part != ""):
+		elems = allAssociationDestinations(core, current, "contains")
+		while (set_len(elems) > 0):
+			elem = set_pop(elems)
+			dict_overwrite(caches["models"], read_attribute(core, elem, "name"), elem)
+			if (value_eq(name, read_attribute(core, elem, "name"))):
+				return elem!
+	else:
+		return current!
+
+	log("NOT FOUND")
+	return ""!
 
 String function get_service_id(name : String):
 	Element services
@@ -356,12 +337,15 @@ String function create_folders(user_id : String, folder_name : String):
 	// Go through folders first
 	while (i < list_len(hierarchy)):
 		elem = list_read(hierarchy, i)
-		cummul = string_join(cummul + "/", elem)
+		if (cummul == ""):
+			cummul = elem
+		else:
+			cummul = string_join(cummul + "/", elem)
 
 		if (get_entry_id(cummul) == ""):
 			// Element does not exist yet!
 			new_entry = instantiate_node(core, "Folder", "")
-			instantiate_attribute(core, new_entry, "name", elem)
+			instantiate_attribute(core, new_entry, "name", cummul)
 			instantiate_attribute(core, new_entry, "permissions", "200")
 			instantiate_link(core, "contains", "", prev, new_entry)
 			instantiate_link(core, "group", "", new_entry, get_group_id("nobody"))
@@ -370,13 +354,13 @@ String function create_folders(user_id : String, folder_name : String):
 		prev = get_entry_id(cummul)
 		i = i + 1
 
-	log("Create of folders " + folder_name)
-	log("Results in " + prev)
 	return prev!
 
 String function store_entry(model_id : String, full_name : String, user_id : String):
 	String prev
+	log("Creating folders for " + full_name)
 	prev = create_folders(user_id, get_foldername(full_name))
+	log("Created folders up to: " + cast_v2s(read_attribute(core, prev, "name")))
 	instantiate_link(core, "contains", "", prev, model_id)
 	return get_filename(full_name)!
 
@@ -1231,9 +1215,9 @@ String function cmd_model_list(user_id : String, location : String):
 			while (set_len(models) > 0):
 				m = set_pop(models)
 				if (is_nominal_instance(core, m, "Folder")):
-					result = result + string_join(read_attribute(core, m, "name"), "/\n")
+					result = result + (get_filename(read_attribute(core, m, "name")) + "/\n")
 				else:
-					result = result + string_join(read_attribute(core, m, "name"), "\n")
+					result = result + (get_filename(read_attribute(core, m, "name")) + "\n")
 			return result!
 		else:
 			return "Permission denied to folder: " + location!
@@ -1261,9 +1245,9 @@ String function cmd_model_list_full(user_id : String, location : String):
 				owner = read_attribute(core, set_pop(allAssociationDestinations(core, m, "owner")), "name")
 				group = read_attribute(core, set_pop(allAssociationDestinations(core, m, "group")), "name")
 				if (is_nominal_instance(core, m, "Folder")):
-					name = string_join(read_attribute(core, m, "name"), "/")
+					name = get_filename(read_attribute(core, m, "name")) + "/"
 				else:
-					name = read_attribute(core, m, "name")
+					name = get_filename(read_attribute(core, m, "name"))
 				result = result + (((((((permissions + " ") + owner) + " ") + group) + " ") + name) + "\n")
 			return result!
 		else: