-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Rework generation of the VID #5737
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ use crate::{ | |
| derive::CacheWeight, | ||
| prelude::{lazy_static, q, r, s, CacheWeight, QueryExecutionError}, | ||
| runtime::gas::{Gas, GasSizeOf}, | ||
| schema::{EntityKey, EntityType}, | ||
| schema::{input::VID_FIELD, EntityKey, EntityType}, | ||
| util::intern::{self, AtomPool}, | ||
| util::intern::{Error as InternError, NullValue, Object}, | ||
| }; | ||
|
|
@@ -910,6 +910,29 @@ impl Entity { | |
| Id::try_from(self.get("id").unwrap().clone()).expect("the id is set to a valid value") | ||
| } | ||
|
|
||
| /// Return the VID of this entity and if its missing or of a type different than | ||
| /// i64 it panics. | ||
| pub fn vid(&self) -> i64 { | ||
| self.get(VID_FIELD) | ||
| .expect("the vid must be set") | ||
| .as_int8() | ||
| .expect("the vid must be set to a valid value") | ||
| } | ||
|
|
||
| /// Sets the VID of the entity. The previous one is returned. | ||
| pub fn set_vid(&mut self, value: i64) -> Result<Option<Value>, InternError> { | ||
| self.0.insert(VID_FIELD, value.into()) | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One additional thought: it would be great if we could guarantee that an entity is always constructed with the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the suggestion but would like to postpone it together with the testing request above for a later stage. WDYT?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test for the VID order is implemented now: 166c909
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am fine with postponing the enforcement of having a |
||
|
|
||
| /// Sets the VID if it's not already set. Should be used only for tests. | ||
| #[cfg(debug_assertions)] | ||
| pub fn set_vid_if_empty(&mut self) { | ||
| let vid = self.get(VID_FIELD); | ||
| if vid.is_none() { | ||
| let _ = self.set_vid(100).expect("the vid should be set"); | ||
| } | ||
| } | ||
|
|
||
| /// Merges an entity update `update` into this entity. | ||
| /// | ||
| /// If a key exists in both entities, the value from `update` is chosen. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.