Skip to content
This repository has been archived by the owner on Jun 3, 2020. It is now read-only.

Commit

Permalink
loading all statements for resource attributes into array to avoid ad…
Browse files Browse the repository at this point in the history
…ditional query to repository for each attribute
  • Loading branch information
glappen committed Feb 10, 2011
1 parent 74040c4 commit c373208
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/spira/resource/instance_methods.rb
Expand Up @@ -78,22 +78,22 @@ def reload(opts = {})
# @return [Hash{Symbol => Any}] attributes
# @private
def reload_attributes()
statements = self.class.repository_or_fail.query(:subject => @subject)
statements = self.class.repository_or_fail.query(:subject => @subject).to_a
attributes = {}

# Set attributes for each statement corresponding to a predicate
self.class.properties.each do |name, property|
if self.class.is_list?(name)
values = Set.new
collection = statements.query(:subject => @subject, :predicate => property[:predicate]) unless statements.empty?
collection = statements.select{|s| s.subject == @subject && s.predicate == property[:predicate]} unless statements.empty?
unless collection.nil?
collection.each do |statement|
values << self.class.build_value(statement,property[:type], @cache)
end
end
attributes[name] = values
else
statement = statements.query(:subject => @subject, :predicate => property[:predicate]).first unless statements.empty?
statement = statements.select{|s| s.subject == @subject && s.predicate == property[:predicate]}.first unless statements.empty?
attributes[name] = self.class.build_value(statement, property[:type], @cache)
end
end
Expand Down

0 comments on commit c373208

Please sign in to comment.