Skip to content

Gitlab::EventStore: Load JSON schema only once

Peter Leitzen requested to merge pl-event-store-json-schema into master

What does this MR do and why?

Before this change, every event subclass had its own copy of the JSON schema.

This change ensures that only a single copy (in Event class) is stored to reduce the memory footprint a bit.

Follow-up of !138169 (merged).

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

How to set up and validate locally

# Revert production changes
git checkout master -- lib 

bin/rspec spec/lib/gitlab/event_store/event_spec.rb
/home/peter/devel/gitlab/gdk/gitlab/spec/deprecation_warnings.rb:13: warning: Ignored warnings for Ruby < 3.2 are no longer necessary.
Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}

Randomized with seed 64807

Gitlab::EventStore::Event
  # order random
  when schema is not defined
    raises an error on initialization
  when schema is defined
    schema validation
      when data matches the schema
        initializes the event correctly
      when some properties are missing
        expects all properties to be present
      when schema is invalid
        raises an error
        does not store JSON schema on subclass (FAILED - 1)
      when required properties are present as well as unknown properties
        initializes the event correctly
        validates schema
      when data is not a Hash
        raises an error

Failures:

  1) Gitlab::EventStore::Event when schema is defined schema validation when schema is invalid does not store JSON schema on subclass
     Failure/Error: expect(event_class.instance_variables).not_to include(:@json_schema)

       expected [:@json_schema, :@json_schema_valid] not to include :@json_schema
       Diff:
       @@ -1 +1 @@
       -[:@json_schema]
       +[:@json_schema, :@json_schema_valid]

     # ./spec/lib/gitlab/event_store/event_spec.rb:100:in `block (5 levels) in <top (required)>'
     # ./spec/support/system_exit_detected.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.06511 seconds (files took 3.02 seconds to load)
8 examples, 1 failure

Failed examples:

rspec ./spec/lib/gitlab/event_store/event_spec.rb:97 # Gitlab::EventStore::Event when schema is defined schema validation when schema is invalid does not store JSON schema on subclass

Randomized with seed 64807
Edited by Peter Leitzen

Merge request reports

Loading