Implement the integration with Firebase #25
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What's changed:
Implements the integration with Firebase
Save:
Data is saved to the Realtime database under the arbitrarily defined
/machines.json
.Each record is defined as
"<id>": { "machineJsonBlob": "<serialized machine state>" }
.The
<id>
is generated by the Realtime database if none exists.The reason behind this design is that the Realtime database discourages nesting data structure [ref].
Since our use case here is very simple, i.e., saving/fetching machine state by id, flattening the state to a JSON string seems to be the most straightforward implementation.
We also wrap it in an object so that if we want to add some metadata in the future, we can add quickly without disrupting the existing structure.
Note: optimization isn't really taken into consideration in the current design, given the constraints posed by the legacy code and the expected traffic/usage (which I think we can keep under free tier of firebase easily?).
machineId
in the machine state.Load:
It finds the matched
id
from url and issues a GET request and load fetched machine if found, otherwise redirecting to/machine_not_found
.Setup deployment (manually)
Caveats:
database.rules.json
)upload/download tests
after deployment (though at least in my production deployment, they function without issue).What's not changed:
What's not in scope of this cl:
machineId
and then flatten), and post to Realtime db.