ea 0.6.167 → 0.6.168

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: 5adeaa57c0343b644501c9413dfa0a3b1e3f220ab0924ab79dc8c89e0e396047
4
- data.tar.gz: 3d1e06b23d4c4ea4bcdfa8b5b028183f18524975bcf19f9ed1c728a3407412a4
3
+ metadata.gz: '090f1fb06dd45d8a7e52fdb723d878cb05511eee38d52427841bd988cda57a2d'
4
+ data.tar.gz: a0386f3f4e6272498094aa66bfaab99e56e103ef64528022bbd6b44f8e248f20
5
5
  SHA512:
6
- metadata.gz: f1dae66ae0da9917a1b14bb67bbb492b945cf215d357c4f3b3c0753eeee3476444da8c7b0d31e4806e7d667161f3ecb760afb9e002ddecbab8ed909ef1bf1435
7
- data.tar.gz: bce07ec117097f324e165203745d54f145835bfe1ae7885398b294186a85640fab402e3e792b24d007c42c001c62250c4e50baea42c52dc1acfc044e9cfacf92
6
+ metadata.gz: 129810cd09fe475f5f65495c69a3cc7dd21428e458777d0bd0fe3a91ea360247c2eab96a5f5f4ecf821eb715e641ebc63caafc687786998076ee24f04b34e485
7
+ data.tar.gz: d542b2a4aa938c7e4aa052b6d414097000c2418b997eda660c47988fb9ca2a3db3de4ef5009db21334b09af71dc4d1c66b624a1c76e477fb2c25c0506e6c0a70
@@ -16,9 +16,6 @@ module Ea
16
16
  # classes = database.objects.find_by_type("Class")
17
17
  # obj = database.find_object(123)
18
18
  class Database
19
- # @return [Hash<Symbol, Array>] Collections of records by name
20
- attr_reader :collections
21
-
22
19
  # @return [String] Path to the QEA file
23
20
  attr_reader :qea_path
24
21
 
@@ -26,9 +23,20 @@ module Ea
26
23
  @qea_path = qea_path
27
24
  @connection = connection
28
25
  @collections = {}
26
+ @deferred = {}
29
27
  @mutex = Mutex.new
30
28
  end
31
29
 
30
+ # Collections of records by name. Resolves every deferred table
31
+ # first: direct-hash readers (lint rules, the SVG emitter) must
32
+ # observe the complete data, same as before lazy tables existed.
33
+ #
34
+ # @return [Hash<Symbol, Array>] loaded collections
35
+ def collections
36
+ resolve_all!
37
+ @collections
38
+ end
39
+
32
40
  # Set database connection
33
41
  #
34
42
  # @param connection [SQLite3::Database] Database connection
@@ -97,6 +105,29 @@ module Ea
97
105
  end
98
106
  end
99
107
 
108
+ # Register a lazy table load: the block resolves the collection
109
+ # on first access. Keeps row models out of memory for tables a
110
+ # consumer never touches (e.g. the diagram trio on the render
111
+ # path), and defers the model-instantiation cost (the dominant
112
+ # share of load time) until the data is actually read.
113
+ #
114
+ # @param name [Symbol] collection name
115
+ # @param loader [Proc] resolves to the record Array when called
116
+ # @return [void]
117
+ def defer_collection(name, &loader)
118
+ @mutex.synchronize do
119
+ @deferred[name.to_sym] = loader
120
+ end
121
+ end
122
+
123
+ # Collections resolved so far — the observability counterpart of
124
+ # {#collection_names} for deferred loading.
125
+ #
126
+ # @return [Array<Symbol>] sorted names of loaded collections
127
+ def loaded_collection_names
128
+ @mutex.synchronize { @collections.keys.sort }
129
+ end
130
+
100
131
  COLLECTION_ACCESSORS = %i[
101
132
  attributes operations operation_params connectors packages
102
133
  diagrams diagram_objects diagram_links object_constraints
@@ -143,8 +174,7 @@ module Ea
143
174
  name = TABLE_TO_COLLECTION[table_name]
144
175
  return [] unless name
145
176
 
146
- records = @collections[name]
147
- return [] unless records
177
+ records = fetch(name)
148
178
 
149
179
  # t_object is wrapped in ObjectRepository — call .all to
150
180
  # get the plain Array that validators expect.
@@ -153,7 +183,7 @@ module Ea
153
183
 
154
184
  COLLECTION_ACCESSORS.each do |name|
155
185
  define_method(name) do
156
- @collections[name] || []
186
+ fetch(name)
157
187
  end
158
188
  end
159
189
 
@@ -163,9 +193,7 @@ module Ea
163
193
  def objects
164
194
  return @objects if defined?(@objects)
165
195
 
166
- @objects = Repositories::ObjectRepository.new(
167
- @collections[:objects] || []
168
- )
196
+ @objects = Repositories::ObjectRepository.new(fetch(:objects))
169
197
  end
170
198
 
171
199
  # Get statistics for all collections
@@ -181,6 +209,7 @@ module Ea
181
209
  # # ...
182
210
  # # }
183
211
  def stats
212
+ resolve_all!
184
213
  @collections.each_with_object({}) do |(name, records), hash|
185
214
  hash[name.to_s] = records.size
186
215
  end
@@ -190,6 +219,7 @@ module Ea
190
219
  #
191
220
  # @return [Integer] Total record count
192
221
  def total_records
222
+ resolve_all!
193
223
  @collections.values.sum(&:size)
194
224
  end
195
225
 
@@ -309,17 +339,34 @@ module Ea
309
339
  #
310
340
  # @return [Boolean] true if no collections loaded
311
341
  def empty?
312
- @collections.empty? || total_records.zero?
342
+ total_records.zero?
313
343
  end
314
344
 
315
345
  # Get collection names
316
346
  #
317
- # @return [Array<Symbol>] Array of collection names
347
+ # @return [Array<Symbol>] Array of collection names, including
348
+ # tables registered but not yet loaded
318
349
  def collection_names
319
- @collections.keys
350
+ (@collections.keys + @deferred.keys).sort
320
351
  end
321
352
 
322
- # Freeze all collections to make database immutable
353
+ # Freeze loaded collections (records immutable) without forcing
354
+ # deferred tables and without freezing the container itself —
355
+ # internal lazy state (table resolution, lookup-index memoization)
356
+ # keeps working after seal. The loader seals instead of freezing
357
+ # so a sealed container can still answer accesses for tables it
358
+ # has not touched yet.
359
+ #
360
+ # @return [self]
361
+ def seal
362
+ @collections.each_value(&:freeze)
363
+ self
364
+ end
365
+
366
+ # Freeze everything: resolve all deferred tables, build all
367
+ # lookup indexes, freeze the collections and the container.
368
+ # Consumers wanting a hard-frozen database call this explicitly;
369
+ # the loader uses #seal to keep lazy resolution available.
323
370
  #
324
371
  # @return [self]
325
372
  def freeze
@@ -331,6 +378,30 @@ module Ea
331
378
 
332
379
  private
333
380
 
381
+ # Resolve one collection, loading a deferred table on first
382
+ # access. Resolution is single-shot and deterministic; the
383
+ # mutex keeps concurrent first accesses from double-loading.
384
+ #
385
+ # @param name [Symbol] collection name
386
+ # @return [Array, Repositories::ObjectRepository] the records
387
+ def fetch(name)
388
+ @mutex.synchronize do
389
+ loader = @deferred.delete(name)
390
+ @collections[name] = loader.call.freeze if loader
391
+ @collections[name] || []
392
+ end
393
+ end
394
+
395
+ # Resolve every deferred table. Used by whole-database readers
396
+ # (stats, total_records, collections) whose answers are defined
397
+ # over the complete data.
398
+ #
399
+ # @return [void]
400
+ def resolve_all!
401
+ names = @mutex.synchronize { @deferred.keys.dup }
402
+ names.each { |name| fetch(name) }
403
+ end
404
+
334
405
  # @param name [String] SQL identifier from the EA schema
335
406
  # @return [String] double-quoted, escaped identifier
336
407
  def quote_ident(name)
@@ -183,9 +183,8 @@ module Ea
183
183
  # The Loaded graph shape the table renders consume. Classes are
184
184
  # constructed per package on demand and memoized on the
185
185
  # context's caches; the database stays the single source.
186
- class LazyGraph < Struct.new(:parser, :uml_document, :drop_options,
187
- :xmi_id_index, keyword_init: true)
188
- end
186
+ LazyGraph = Struct.new(:parser, :uml_document, :drop_options,
187
+ :xmi_id_index, keyword_init: true)
189
188
 
190
189
  # Document facade answering RootDrop's reads: name + packages.
191
190
  class LazyDocument
@@ -236,26 +235,26 @@ module Ea
236
235
 
237
236
  def classes
238
237
  @context.database.objects_in_package(@package.package_id)
239
- .select(&:uml_class?)
240
- .map { |row| @context.klass_for(row.ea_object_id) }
241
- .compact
238
+ .select(&:uml_class?)
239
+ .map { |row| @context.klass_for(row.ea_object_id) }
240
+ .compact
242
241
  end
243
242
 
244
243
  def enums
245
244
  @context.database.objects_in_package(@package.package_id)
246
- .select(&:enumeration?)
247
- .filter_map { |row| @context.enum_for(row.ea_object_id) }
245
+ .select(&:enumeration?)
246
+ .filter_map { |row| @context.enum_for(row.ea_object_id) }
248
247
  end
249
248
 
250
249
  def data_types
251
250
  @context.database.objects_in_package(@package.package_id)
252
- .select(&:data_type?)
253
- .filter_map { |row| @context.data_type_for(row.ea_object_id) }
251
+ .select(&:data_type?)
252
+ .filter_map { |row| @context.data_type_for(row.ea_object_id) }
254
253
  end
255
254
 
256
255
  def packages
257
256
  @context.database.child_packages_for(@package.package_id)
258
- .map { |row| LazyPackage.new(@context, row) }
257
+ .map { |row| LazyPackage.new(@context, row) }
259
258
  end
260
259
 
261
260
  def diagrams
@@ -439,21 +438,18 @@ module Ea
439
438
  context = @context
440
439
  database = context.database
441
440
 
442
- database.objects.all.each do |object|
443
- next unless object.ea_guid
444
-
445
- next unless Ea::GuidFormat.ea_guid_to_xmi_id(object.ea_guid) == xmi_id
446
-
447
- return case object
448
- when ->(o) { o.uml_class? || o.interface? }
449
- context.klass_for(object.ea_object_id)
450
- when lambda(&:enumeration?)
451
- context.enum_for(object.ea_object_id)
452
- when lambda(&:data_type?)
453
- context.data_type_for(object.ea_object_id)
454
- end
441
+ guid = Ea::GuidFormat.xmi_id_to_ea_guid(xmi_id)
442
+ object = guid && database.find_object_by_guid(guid)
443
+ return unless object
444
+
445
+ case object
446
+ when ->(o) { o.uml_class? || o.interface? }
447
+ context.klass_for(object.ea_object_id)
448
+ when lambda(&:enumeration?)
449
+ context.enum_for(object.ea_object_id)
450
+ when lambda(&:data_type?)
451
+ context.data_type_for(object.ea_object_id)
455
452
  end
456
- nil
457
453
  end
458
454
  end
459
455
  end
@@ -98,6 +98,13 @@ module Ea
98
98
 
99
99
  # Load entire database
100
100
  #
101
+ # Tables register as deferred loads rather than materializing
102
+ # up front: row-model instantiation dominates load cost, and
103
+ # consumers that never touch a table (the diagram trio on the
104
+ # klass-table path) no longer pay for it. First access loads
105
+ # through a reopened connection — nothing keeps the file
106
+ # handle open (a persistent handle locks the file on Windows).
107
+ #
101
108
  # @return [Database] Populated database instance
102
109
  # @raise [Errno::ENOENT] if QEA file not found
103
110
  # @raise [SQLite3::Exception] if database access fails
@@ -106,16 +113,20 @@ module Ea
106
113
  db = @connection.connection
107
114
 
108
115
  database = Database.new(@qea_path, db)
109
- # Kept for on-demand blob fetches after load (the connection
110
- # itself closes in ensure; Database reopens per fetch).
116
+ # Kept for on-demand blob fetches and deferred table loads
117
+ # after load (the connection itself closes in ensure;
118
+ # Database reopens per fetch/resolve).
111
119
  database.blob_connection = @connection
112
120
 
113
121
  @config.enabled_tables.each do |table_def|
114
- records = load_table_records(db, table_def)
115
- database.add_collection(table_def.collection_name, records)
122
+ database.defer_collection(table_def.collection_name) do
123
+ @connection.with_connection do |live|
124
+ load_table_records(live, table_def)
125
+ end
126
+ end
116
127
  end
117
128
 
118
- database.freeze
129
+ database.seal
119
130
  ensure
120
131
  # All tables are in memory; nothing keeps the handle open, and
121
132
  # an open handle locks the file on Windows. Blob fetches go
data/lib/ea/version.rb CHANGED
@@ -4,5 +4,5 @@ module Ea
4
4
  # Gem release version. Extracted to its own file so the
5
5
  # `gem-release` tool's `gem bump` can find and update it via the
6
6
  # standard `lib/<gem>/version.rb` convention.
7
- VERSION = "0.6.167"
7
+ VERSION = "0.6.168"
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ea
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.167
4
+ version: 0.6.168
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-11-28 00:00:00.000000000 Z
11
+ date: 2026-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lutaml-model