Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache Module to Edge relation in ModuleManager #164

Open
github-actions bot opened this issue Mar 7, 2022 · 0 comments
Open

Cache Module to Edge relation in ModuleManager #164

github-actions bot opened this issue Mar 7, 2022 · 0 comments
Labels
priority: low todo type: enhancement new feature or request type: maintenance requires maintenance

Comments

@github-actions
Copy link

github-actions bot commented Mar 7, 2022

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

@github-actions github-actions bot added the todo label Mar 7, 2022
@caspiano caspiano removed their assignment Mar 7, 2022
@caspiano caspiano added type: enhancement new feature or request type: maintenance requires maintenance labels Mar 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: low todo type: enhancement new feature or request type: maintenance requires maintenance
Projects
None yet
Development

No branches or pull requests

1 participant