Skip to content
Snippets Groups Projects
Commit 539f1338 authored by Benedikt Heinrichs's avatar Benedikt Heinrichs
Browse files

Fix: Add a Wrapper Graph for better Performance

parent 712b29f4
No related branches found
No related tags found
No related merge requests found
...@@ -99,8 +99,6 @@ namespace TrellisMigrator.Implementations ...@@ -99,8 +99,6 @@ namespace TrellisMigrator.Implementations
} }
var fileGraphs = WrapRequest(() => ListGraphs(resourceGraphName + "/")); var fileGraphs = WrapRequest(() => ListGraphs(resourceGraphName + "/"));
foreach (var fileGraph in fileGraphs) foreach (var fileGraph in fileGraphs)
{ {
if (fileGraph.ToString() != resourceGraphName + "/") if (fileGraph.ToString() != resourceGraphName + "/")
......
...@@ -61,6 +61,23 @@ namespace TrellisMigrator ...@@ -61,6 +61,23 @@ namespace TrellisMigrator
foreach (var graph in graphs) foreach (var graph in graphs)
{ {
Console.WriteLine($" ({graph.BaseUri})"); Console.WriteLine($" ({graph.BaseUri})");
if (graph is WrapperGraph)
{
var wrapperGraph = (WrapperGraph)graph;
// Chunking since the size otherwise can be too large
foreach (var triples in wrapperGraph.AssertList.Chunk(100))
{
WrapRequest(() => ReadWriteSparqlConnector.UpdateGraph(graph.BaseUri, triples, new List<Triple>()));
}
// Chunking since the size otherwise can be too large
foreach (var triples in wrapperGraph.RetractList.Chunk(100))
{
WrapRequest(() => ReadWriteSparqlConnector.UpdateGraph(graph.BaseUri, new List<Triple>(), triples));
}
}
else
{
var exists = WrapRequest(() => HasGraph(graph.BaseUri)); var exists = WrapRequest(() => HasGraph(graph.BaseUri));
if (exists) if (exists)
{ {
...@@ -72,10 +89,12 @@ namespace TrellisMigrator ...@@ -72,10 +89,12 @@ namespace TrellisMigrator
} }
// Chunking since the size otherwise can be too large // Chunking since the size otherwise can be too large
// Don't change to only addition of triples, otherwise this could break things
foreach (var triples in graph.Triples.Chunk(100)) foreach (var triples in graph.Triples.Chunk(100))
{ {
WrapRequest(() => ReadWriteSparqlConnector.UpdateGraph(graph.BaseUri, triples, new List<Triple>())); WrapRequest(() => ReadWriteSparqlConnector.UpdateGraph(graph.BaseUri, triples, new List<Triple>()));
} }
}
Console.WriteLine($" - Graph {graph.BaseUri} added successfully"); Console.WriteLine($" - Graph {graph.BaseUri} added successfully");
Console.WriteLine(); Console.WriteLine();
...@@ -158,10 +177,13 @@ namespace TrellisMigrator ...@@ -158,10 +177,13 @@ namespace TrellisMigrator
// Returns an empty graph, if the graph does not exists // Returns an empty graph, if the graph does not exists
public IGraph GetGraph(Uri graphUri) public IGraph GetGraph(Uri graphUri)
{ {
var graph = new Graph(); var graph = new WrapperGraph();
ReadWriteSparqlConnector.LoadGraph(graph, graphUri.AbsoluteUri); ReadWriteSparqlConnector.LoadGraph(graph, graphUri.AbsoluteUri);
graph.AssertList.Clear();
graph.RetractList.Clear();
return graph; return graph;
} }
......
using VDS.RDF;
namespace TrellisMigrator
{
public class WrapperGraph : Graph
{
public List<Triple> AssertList { get; set; }
public List<Triple> RetractList { get; set; }
public WrapperGraph() : base()
{
AssertList = new List<Triple>();
RetractList = new List<Triple>();
}
public override bool Assert(Triple t)
{
AssertList.Add(t);
return base.Assert(t);
}
public override bool Assert(IEnumerable<Triple> triples)
{
AssertList.AddRange(triples);
return base.Assert(triples);
}
public override bool Retract(Triple t)
{
RetractList.Add(t);
return base.Retract(t);
}
public override bool Retract(IEnumerable<Triple> triples)
{
RetractList.AddRange(triples);
return base.Retract(triples);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment