Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RDF::Graph should use Repository#insert_statements #220

Closed
no-reply opened this issue Oct 22, 2015 · 3 comments
Closed

RDF::Graph should use Repository#insert_statements #220

no-reply opened this issue Oct 22, 2015 · 3 comments
Assignees
Milestone

Comments

@no-reply
Copy link
Member

RDF::Graph relies on Writable#insert_statements, which always inserts statements individually.

Some (hopefully all) Repository implementations that interact with upstream data implement #insert_statements as a single request. Using Graph to interact with a repository results in sending individual requests, regardless of the Repository implementation.

e.g., the following results in some_statements.count individual requests to some_repository:

my_graph = RDF::Graph.new(RDF::URI('http://ex.org/my_graph'), data: some_repository)
my_graph << some_statements

I'm working on a fix for this.

@no-reply no-reply self-assigned this Oct 22, 2015
@gkellogg
Copy link
Member

I think the way to do this may be to redirect to Repository#insert_statements and update each statement's graph_name using map or in an enumerator, depending on the form of statements. Note that insert_statements has a special case if the first element is an Enumerable.

@no-reply
Copy link
Member Author

I came up with:

    def insert_statements(statements)
      enum = statements.respond_to?(:each_statement) ? statements.each_statement : statements
      @data.insert(*enum.map { |st| statement = st.dup; statement.graph_name = graph_name; statement })
    end

But planning to dig around a little more to make sure that's the best plan.

@gkellogg
Copy link
Member

There was a recent change to make sure that it could take an enumerator, as the *enum.map... can create too many arguments; see #214 (comment).

I was thinking of something like the following:

def insert_statements(statements)
  enum = Enumerable::Enumerator.new do |yielder|
    this.send(statements.respond_to?(:each_statement) ? :each_statement : :each) do |st|
      st = st.dup
      st.graph_name = graph_name;
      yielder << st
    end
  end
  @data.insert_statements(enum)
end

This allows @data.insert_statements to take chunks of statements to insert without evaluating everything at once.

@gkellogg gkellogg added this to the 2.0 milestone Oct 30, 2015
no-reply pushed a commit that referenced this issue Nov 3, 2015
Graph previously avoided the multi-statement insert interfaces of its
underlying `Repository`. By adding `#insert_statements`, we can use that
interface, saving round-trips to external repositories.

Closes #220.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants