Skip to content

Cache Module to Edge relation in ModuleManager #164

@github-actions

Description

@github-actions

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...

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

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions