discourse/spec/lib/service
Loïc Guitaut 1a9f577044 DEV: Don’t check model validity when no changes have been made
When fetching a model using the `model` step in a service, if that model
is an `ActiveRecord` object, we check if it’s in a valid state. While
this is useful when manipulating the model or when we create a new one,
it’s not the case for a model we just pulled from the DB, as it should
be valid.

In some cases, running the validations can be costly (it can lead to N+1
queries if the model validates associated items for example).

This patch introduces a small optimization by checking if the model has
any pending changes on it, thus requiring validation. If that’s not the
case, we just skip the validation part, as the model should be valid
anyway.
2025-06-20 09:09:33 +02:00
..
runner_spec.rb DEV: Don’t check model validity when no changes have been made 2025-06-20 09:09:33 +02:00
steps_inspector_spec.rb DEV: Don’t check model validity when no changes have been made 2025-06-20 09:09:33 +02:00