-
Notifications
You must be signed in to change notification settings - Fork 1
Description
The Module to Edge relation is very unlikely to change, so keeping a lookup will save a lot of queries, especially with a high volume of executes.
To ensure correctness, updates to edge_id MUST be captured in a change listener.
A simple place to do so would be below...
core/src/placeos-core/mappings/module_names.cr
Lines 17 to 24 in b938d43
| def process_resource(action : RethinkORM::Changefeed::Event, resource mod : PlaceOS::Model::Module) : Resource::Result | |
| return Resource::Result::Skipped unless action.updated? | |
| ModuleNames.update_module_mapping(mod, module_manager) | |
| rescue exception | |
| Log.error(exception: exception) { {message: "while updating mapping for module", name: mod.name, custom_name: mod.custom_name} } | |
| raise Resource::ProcessingError.new(mod.name, exception.message, cause: exception) | |
| end |
However, to ensure encapsulation and ease of testing, a separate listener on the modules table can be initiated.
An alternative to a listener would be ensuring that edge_id cannot be changed via mass assignment, and it can be assumed to be static, removing the need to consider cache stagnation.
Corresponding TODO
core/src/placeos-core/module_manager.cr
Lines 256 to 262 in b938d43
| edge_id = case mod | |
| in Model::Module | |
| mod.edge_id if mod.on_edge? | |
| in String | |
| # TODO: Cache `Module` to `Edge` relation in `ModuleManager` | |
| Model::Module.find!(mod).edge_id if Model::Module.has_edge_hint?(mod) | |
| end |