ldp 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2674ad59a41058590a896596558af878b3374fe570b5b082a618ff11125d55e6
4
- data.tar.gz: daca7e05e686169d4518e5c5d1c0495aef46f461e74dabbfffc36ef148e2e41c
3
+ metadata.gz: db21a1bac397bd2aebca07c57331dcbe7ab895642f2505728b543aa4ef5a1cdd
4
+ data.tar.gz: 6f4e2a5195c5ceb69b60b7f6d4b3f471e224b7c80dfb647342c422234a9bc615
5
5
  SHA512:
6
- metadata.gz: bf52366a7386e19f4e777aaab2fd789f168263d645940dbd7660abe0fa14b22422bd59caf12da4c050908f47c5b9c9c9e5fde0b50f56830b21cfe90f1568c445
7
- data.tar.gz: b670c997ba25a63fe2298e336b2dccb7833c3893631a1d3f90cd775de26a559ff08e83d4ef38911a198b341827e48ab74b6fa0dd56e28d6e2a1ca4c2757b038e
6
+ metadata.gz: de19de70dba6611052910192d18f2f3f28d5d4821bbe402385e2e26a8bfeddfa64559727f572b81dffb5f2fc7dd14ab3e7f2b12f0968734ec3a8d97f2933b1b9
7
+ data.tar.gz: c77a9e35d78be05782fb958740d5615ad51b9f8a42b311327d8f9c2db0a710fb42e58533ebe5d9b830800238da53e49277afa9cadb252c13b87cf9f907732244
data/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.0.2](https://github.com/samvera/ldp/tree/1.0.1) (2021-05-14)
4
+
5
+ [Full Changelog](https://github.com/samvera/ldp/compare/v1.0.1...1.0.2)
6
+
7
+ This release includes major performance improvements and memory optimizations.
8
+
9
+ These optimizations replace linear complexity data access operations with
10
+ constant-time equivalents. They also prevent repeated wholesale copying of
11
+ (potentially large) RDF graphs in-memory when deserializing LDP responses.
12
+
13
+ This should result in broad performance improvements in all cases. The biggest
14
+ impact will be on RDF Sources with many `ldp:contains` relationships.
15
+
16
+ **Merged pull requests:**
17
+
18
+ - don't loop over statements manually; use the library [#118](https://github.com/samvera/ldp/pull/118)
19
+ - optimize subject filtering [#119](https://github.com/samvera/ldp/pull/119)
20
+ - Adding CONTRIBUTING.md This was uploaded via automation. [#116](https://github.com/samvera/ldp/pull/116)
21
+ - fix a regression in handling for custom graph classes in `RDFSource` [#120](https://github.com/samvera/ldp/pull/120)
22
+
3
23
  ## [1.0.1](https://github.com/samvera/ldp/tree/1.0.1) (2020-06-12)
4
24
 
5
25
  [Full Changelog](https://github.com/samvera/ldp/compare/v1.0.1-beta1...1.0.1)
data/CONTRIBUTING.md CHANGED
@@ -22,6 +22,28 @@ https://wiki.duraspace.org/display/samvera/Samvera+Community+Intellectual+Proper
22
22
 
23
23
  You should also add yourself to the `CONTRIBUTORS.md` file in the root of the project.
24
24
 
25
+ ## Language
26
+
27
+ The language we use matters. Today, tomorrow, and for years to come
28
+ people will read the code we write. They will judge us for our
29
+ design, logic, and the words we use to describe the system.
30
+
31
+ Our words should be accessible. Favor descriptive words that give
32
+ meaning while avoiding reinforcing systemic inequities. For example,
33
+ in the Samvera community, we should favor using allowed\_list instead
34
+ of whitelist, denied\_list instead of blacklist, or source/copy
35
+ instead of master/slave.
36
+
37
+ We're going to get it wrong, but this is a call to keep working to
38
+ make it right. View our code and the words we choose as a chance to
39
+ have a conversation. A chance to grow an understanding of the systems
40
+ we develop as well as the systems in which we live.
41
+
42
+ See [“Blacklists” and “whitelists”: a salutary warning concerning the
43
+ prevalence of racist language in discussions of predatory
44
+ publishing](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6148600/) for
45
+ further details.
46
+
25
47
  ## Contribution Tasks
26
48
 
27
49
  * Reporting Issues
@@ -34,7 +56,7 @@ You should also add yourself to the `CONTRIBUTORS.md` file in the root of the pr
34
56
  ### Reporting Issues
35
57
 
36
58
  * Make sure you have a [GitHub account](https://github.com/signup/free)
37
- * Submit a [Github issue](https://github.com/samvera/ldp/issues) by:
59
+ * Submit a [Github issue](https://github.com/samvera/ldp/issues/) by:
38
60
  * Clearly describing the issue
39
61
  * Provide a descriptive summary
40
62
  * Explain the expected behavior
@@ -67,40 +67,36 @@ module Ldp
67
67
  private
68
68
 
69
69
  ##
70
+ # @note tries to avoid doing a large scale copy of the {RDF::Repository}
71
+ # data structure by using the existing {Ldp::Response#graph} if
72
+ # {#graph_class} is {RDF::Graph}. otherwise, it tries to instantiate a
73
+ # new graph projected over the same underlying {RDF::Graph#data}. finally,
74
+ # if {#graph_class}'s initailizer doesn't accept a `data:` parameter, it
75
+ # shovels {Ldp::Response#graph} into a new object of that class.
76
+ #
70
77
  # @param [Faraday::Response] graph query response
71
78
  # @return [RDF::Graph]
72
79
  def response_as_graph(resp)
73
- graph = build_empty_graph
74
- resp.each_statement do |stmt|
75
- graph << stmt
80
+ if graph_class == RDF::Graph
81
+ resp.graph
82
+ else
83
+ graph_class.new(data: resp.graph.data)
76
84
  end
77
- graph
85
+ rescue ArgumentError
86
+ build_empty_graph << resp.graph
78
87
  end
79
88
 
80
89
  ##
81
90
  # @param [RDF::Graph] original_graph The graph returned by the LDP server
82
91
  # @return [RDF::Graph] A graph stripped of any inlined resources present in the original
83
92
  def filtered_graph(original_graph)
84
- inlined_resources = original_graph.query(predicate: RDF::Vocab::LDP.contains).map { |x| x.object }
85
-
86
- # we want to scope this graph to just statements about this model, not contained relations
87
- if inlined_resources.empty?
88
- original_graph
89
- else
90
- graph_without_inlined_resources(original_graph, inlined_resources)
91
- end
92
- end
93
-
94
- def graph_without_inlined_resources(original_graph, inlined_resources)
95
- new_graph = build_empty_graph
93
+ contains_statements = original_graph.query(predicate: RDF::Vocab::LDP.contains)
96
94
 
97
- original_graph.each_statement do |s|
98
- unless inlined_resources.include? s.subject
99
- new_graph << s
100
- end
95
+ contains_statements.each_object do |contained_uri|
96
+ original_graph.delete(original_graph.query(subject: contained_uri))
101
97
  end
102
98
 
103
- new_graph
99
+ original_graph
104
100
  end
105
101
  end
106
102
  end
data/lib/ldp/response.rb CHANGED
@@ -105,9 +105,7 @@ module Ldp
105
105
  # Get the graph for the resource (or a blank graph if there is no metadata for the resource)
106
106
  def graph
107
107
  @graph ||= begin
108
- graph = RDF::Graph.new
109
- each_statement { |s| graph << s }
110
- graph
108
+ RDF::Graph.new << reader
111
109
  end
112
110
  end
113
111
 
@@ -115,6 +113,8 @@ module Ldp
115
113
  reader_for_content_type.new(body, base_uri: page_subject, &block)
116
114
  end
117
115
 
116
+ ##
117
+ # @deprecated use {#graph} instead
118
118
  def each_statement(&block)
119
119
  reader do |reader|
120
120
  reader.each_statement(&block)
@@ -155,17 +155,9 @@ module Ldp
155
155
  # Statements about the page
156
156
  def page
157
157
  @page_graph ||= begin
158
- g = RDF::Graph.new
159
-
160
- if resource?
161
- res = graph.query RDF::Statement.new(page_subject, nil, nil)
162
-
163
- res.each_statement do |s|
164
- g << s
165
- end
166
- end
167
-
168
- g
158
+ page_graph = RDF::Graph.new
159
+ page_graph << graph.query([page_subject, nil, nil]) if resource?
160
+ page_graph
169
161
  end
170
162
  end
171
163
 
data/lib/ldp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ldp
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -107,6 +107,24 @@ describe Ldp::Resource::RdfSource do
107
107
  expect(subject.graph.size).to eql(1)
108
108
  end
109
109
  end
110
+
111
+ context 'with inlined resources' do
112
+ subject { Ldp::Resource::RdfSource.new mock_client, "http://my.ldp.server/existing_object" }
113
+
114
+ let(:simple_graph) do
115
+ graph = RDF::Graph.new
116
+ graph << [RDF::URI.new(), RDF::Vocab::DC.title, "Hello, world!"]
117
+ graph << [RDF::URI.new(), RDF::Vocab::LDP.contains, contained_uri]
118
+ graph << [contained_uri, RDF::Vocab::DC.title, "delete me"]
119
+ end
120
+
121
+ let(:contained_uri) { RDF::URI.new('http://example.com/contained') }
122
+
123
+ it do
124
+ expect(subject.graph.subjects)
125
+ .to contain_exactly(RDF::URI('http://my.ldp.server/existing_object'))
126
+ end
127
+ end
110
128
  end
111
129
 
112
130
  context "When graph_class is overridden" do
@@ -130,5 +148,14 @@ describe Ldp::Resource::RdfSource do
130
148
  it "should use the specified class" do
131
149
  expect(subject.graph).to be_a SpecialGraph
132
150
  end
151
+
152
+ context "with a response body" do
153
+ subject { SpecialResource.new mock_client, "http://my.ldp.server/existing_object" }
154
+
155
+
156
+ it "should use the specified class" do
157
+ expect(subject.graph).to be_a SpecialGraph
158
+ end
159
+ end
133
160
  end
134
161
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ldp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-12 00:00:00.000000000 Z
11
+ date: 2021-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -300,7 +300,7 @@ homepage: https://github.com/projecthydra/ldp
300
300
  licenses:
301
301
  - APACHE2
302
302
  metadata: {}
303
- post_install_message:
303
+ post_install_message:
304
304
  rdoc_options: []
305
305
  require_paths:
306
306
  - lib
@@ -315,8 +315,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
315
315
  - !ruby/object:Gem::Version
316
316
  version: '0'
317
317
  requirements: []
318
- rubygems_version: 3.1.2
319
- signing_key:
318
+ rubygems_version: 3.1.4
319
+ signing_key:
320
320
  specification_version: 4
321
321
  summary: Linked Data Platform client library
322
322
  test_files: