amalgame/commit

IMPROVED: make flushing of stats cache depedent on expand_cache to avoid inconsistencies

authorJacco van Ossenbruggen
Mon May 11 17:22:14 2015 +0200
committerJacco van Ossenbruggen
Mon May 11 17:22:14 2015 +0200
commitf7244306c012df76de6dff782ee36496d88d05e0
treeb662fda68b7bf99787c747504dd340dbe8483b37
parent8adfaf5fcb3f9c83516e592f7d113ad2c3190b2b
Diff style: patch stat
diff --git a/api/ag_process.pl b/api/ag_process.pl
index 38f8515..c3c3ca9 100644
--- a/api/ag_process.pl
+++ b/api/ag_process.pl
@@ -158,7 +158,6 @@ change_ns_if_needed(NS, URI, Strategy, NewStrategy) :-
 	    rdf_unload_graph(Prov),
 	    rdf_retractall(URI, amalgame:publish_ns, OldNS, Strategy),
 	    rdf_assert(URI, amalgame:publish_ns, NS, Strategy),
-	    flush_stats_cache(Strategy),
 	    flush_expand_cache(Strategy),
 	    change_namespace(OldNS, NS, Strategy, NewStrategy)
 	).
diff --git a/api/evaluate.pl b/api/evaluate.pl
index a5b903a..5f802f9 100644
--- a/api/evaluate.pl
+++ b/api/evaluate.pl
@@ -70,7 +70,6 @@ http_data_evaluate(Request) :-
 	strategy_process_entity(Strategy, EvalProcess,  Graph),
 	flush_expand_cache(EvalProcess, Strategy),  % graph cache is now outdated
 	flush_refs_cache(Strategy),                 % to recompute all reference stats
-	flush_stats_cache(Graph, Strategy),         % to recompute G's basic stats
 
 	user_property(User0, url(User)),
 
diff --git a/lib/amalgame/caching.pl b/lib/amalgame/caching.pl
index 8e2721d..fce6572 100644
--- a/lib/amalgame/caching.pl
+++ b/lib/amalgame/caching.pl
@@ -10,9 +10,7 @@
 	      flush_expand_cache/1,     % ?Strategy
 	      flush_expand_cache/2,     % +Id, +Strategy
 	      flush_refs_cache/1,       % ?Strategy
-	      flush_refs_cache/2,
-	      flush_stats_cache/1, % ?Strategy
-	      flush_stats_cache/2  % +Mapping, +Strategy
+	      flush_refs_cache/2
 	  ]).
 
 :- use_module(library(debug)).
@@ -39,13 +37,9 @@
 	   'Minimum execution time to cache intermediate \c
 	   results, defaults to 0.0, caching everything').
 
-
-user:message_hook(make(done(_)), _, _) :-
-	flush_stats_cache(_),
-	nickname_clear_cache,
-	fail.
 user:message_hook(make(done(_)), _, _) :-
 	flush_expand_cache(_),
+	nickname_clear_cache,
 	fail.
 user:message_hook(make(done(_)), _, _) :-
 	flush_prov_cache,
@@ -78,21 +72,6 @@ flush_stats_cache(Id, Strategy) :-
 	;   true
 	).
 
-flush_stats_cache(Strategy) :-
-	flush_mapping_stats_cache(Strategy),
-	flush_virtual_scheme_stats_cache(Strategy).
-
-flush_mapping_stats_cache(Strategy) :-
-	forall(rdf(Mapping, rdf:type, amalgame:'Mapping', Strategy),
-	       (   flush_stats_cache(Mapping, Strategy),
-		   flush_mapped_concepts_cache(Mapping, Strategy)
-	      )
-	      ).
-flush_virtual_scheme_stats_cache(Strategy) :-
-	forall(rdf(Mapping, rdf:type, amalgame:'VirtualConceptScheme', Strategy),
-	       flush_stats_cache(Mapping, Strategy)
-	      ).
-
 flush_refs_cache(Strategy) :-
 	flush_refs_cache(_Mapping,Strategy).
 
@@ -167,6 +146,14 @@ clean_repository :-
 	       )
 	      ).
 
+amalgame_computed_node(Strategy, Id) :-
+	rdf(Id, rdf:type, amalgame:'VirtualConceptScheme', Strategy).
+amalgame_computed_node(Strategy, Id) :-
+	rdf(Id, rdf:type, amalgame:'Mapping', Strategy).
+amalgame_computed_node(Strategy, Id) :-
+	rdfs_individual_of(Id,  amalgame:'Process'),
+	rdf(Id, rdf:type, _, Strategy).
+
 %%	flush_expand_cache(+Strategy)
 %
 %	Retract all cached mappings.
@@ -175,14 +162,16 @@ flush_expand_cache(Strategy) :-
 	del_prov_graphs(Strategy),
 	del_materialized_vocs(Strategy),
 	del_materialized_mappings(Strategy),
-	forall(expand_cache(Id-Strategy, _),
-	       flush_expand_cache(Id, Strategy)
+	forall(amalgame_computed_node(Strategy ,Id),
+	          flush_expand_cache(Id, Strategy)
 	      ).
 
 flush_expand_cache(Id, Strategy) :-
 	(   expand_cache(Id-Strategy, _) % make sure Id is bounded to something in the cache
 	->  retractall(expand_cache(Id-Strategy, _)),
-	    debug(ag_expand, 'Flushed expand mapping cache for results of process ~p', [Id])
+	    debug(ag_expand, 'Flushed expand mapping cache for results of process ~p', [Id]),
+	    flush_stats_cache(Id, Strategy),
+	    flush_mapped_concepts_cache(Id, Strategy)
 	;   true
 	).