Skip to content

Commit a73e9b4

Browse files
committed
[IMP] server: improve performancies of is_field
1 parent 59967f7 commit a73e9b4

File tree

2 files changed

+44
-33
lines changed

2 files changed

+44
-33
lines changed

server/src/core/symbols/class_symbol.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub struct ClassSymbol {
2828
pub body_range: TextRange,
2929
pub _model: Option<ModelData>,
3030
pub noqas: NoqaInfo,
31+
pub(crate) _is_field_class: Rc<RefCell<Option<bool>>>, //cache, do not call directly, use is_field_class() method instead
3132

3233
//Trait SymbolMgr
3334
//--- Body symbols
@@ -57,6 +58,7 @@ impl ClassSymbol {
5758
bases: vec![],
5859
_model: None,
5960
noqas: NoqaInfo::None,
61+
_is_field_class: Rc::new(RefCell::new(None)),
6062
};
6163
res._init_symbol_mgr();
6264
res

server/src/core/symbols/symbol.rs

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2561,44 +2561,53 @@ impl Symbol {
25612561
if !matches!(self.typ(), SymType::CLASS) {
25622562
return false;
25632563
}
2564-
let tree = flatten_tree(&self.get_main_entry_tree(session));
2565-
if compare_semver(session.sync_odoo.full_version.as_str(), "18.1.0") >= Ordering::Equal {
2566-
if tree.len() == 4 && tree[0] == "odoo" && tree[1] == "orm" && (
2567-
tree[2] == "fields_misc" && tree[3] == "Boolean" ||
2568-
tree[2] == "fields_numeric" && tree[3] == "Integer" ||
2569-
tree[2] == "fields_numeric" && tree[3] == "Float" ||
2570-
tree[2] == "fields_numeric" && tree[3] == "Monetary" ||
2571-
tree[2] == "fields_textual" && tree[3] == "Char" ||
2572-
tree[2] == "fields_textual" && tree[3] == "Text" ||
2573-
tree[2] == "fields_textual" && tree[3] == "Html" ||
2574-
tree[2] == "fields_temporal" && tree[3] == "Date" ||
2575-
tree[2] == "fields_temporal" && tree[3] == "Datetime" ||
2576-
tree[2] == "fields_binary" && tree[3] == "Binary" ||
2577-
tree[2] == "fields_binary" && tree[3] == "Image" ||
2578-
tree[2] == "fields_selection" && tree[3] == "Selection" ||
2579-
tree[2] == "fields_reference" && tree[3] == "Reference" ||
2580-
tree[2] == "fields_relational" && tree[3] == "Many2one" ||
2581-
tree[2] == "fields_reference" && tree[3] == "Many2oneReference" ||
2582-
tree[2] == "fields_misc" && tree[3] == "Json" ||
2583-
tree[2] == "fields_properties" && tree[3] == "Properties" ||
2584-
tree[2] == "fields_properties" && tree[3] == "PropertiesDefinition" ||
2585-
tree[2] == "fields_relational" && tree[3] == "One2many" ||
2586-
tree[2] == "fields_relational" && tree[3] == "Many2many" ||
2587-
tree[2] == "fields_misc" && tree[3] == "Id"
2588-
){
2589-
return true;
2590-
}
2564+
let mut cache = self.as_class_sym()._is_field_class.borrow_mut();
2565+
if let Some(is_field_class) = cache.as_ref() {
2566+
return *is_field_class;
25912567
} else {
2592-
if tree.len() == 3 && tree[0] == "odoo" && tree[1] == "fields" {
2593-
if matches!(tree[2].as_str(), "Boolean" | "Integer" | "Float" | "Monetary" | "Char" | "Text" | "Html" | "Date" | "Datetime" |
2594-
"Binary" | "Image" | "Selection" | "Reference" | "Json" | "Properties" | "PropertiesDefinition" | "Id" | "Many2one" | "One2many" | "Many2many" | "Many2oneReference") {
2568+
let tree = &self.get_main_entry_tree(session);
2569+
if compare_semver(session.sync_odoo.full_version.as_str(), "18.1.0") >= Ordering::Equal {
2570+
if tree.0.len() == 3 && tree.1.len() == 1 && tree.0[0] == "odoo" && tree.0[1] == "orm" && (
2571+
tree.0[2] == "fields_misc" && tree.1[0] == "Boolean" ||
2572+
tree.0[2] == "fields_numeric" && tree.1[0] == "Integer" ||
2573+
tree.0[2] == "fields_numeric" && tree.1[0] == "Float" ||
2574+
tree.0[2] == "fields_numeric" && tree.1[0] == "Monetary" ||
2575+
tree.0[2] == "fields_textual" && tree.1[0] == "Char" ||
2576+
tree.0[2] == "fields_textual" && tree.1[0] == "Text" ||
2577+
tree.0[2] == "fields_textual" && tree.1[0] == "Html" ||
2578+
tree.0[2] == "fields_temporal" && tree.1[0] == "Date" ||
2579+
tree.0[2] == "fields_temporal" && tree.1[0] == "Datetime" ||
2580+
tree.0[2] == "fields_binary" && tree.1[0] == "Binary" ||
2581+
tree.0[2] == "fields_binary" && tree.1[0] == "Image" ||
2582+
tree.0[2] == "fields_selection" && tree.1[0] == "Selection" ||
2583+
tree.0[2] == "fields_reference" && tree.1[0] == "Reference" ||
2584+
tree.0[2] == "fields_relational" && tree.1[0] == "Many2one" ||
2585+
tree.0[2] == "fields_reference" && tree.1[0] == "Many2oneReference" ||
2586+
tree.0[2] == "fields_misc" && tree.1[0] == "Json" ||
2587+
tree.0[2] == "fields_properties" && tree.1[0] == "Properties" ||
2588+
tree.0[2] == "fields_properties" && tree.1[0] == "PropertiesDefinition" ||
2589+
tree.0[2] == "fields_relational" && tree.1[0] == "One2many" ||
2590+
tree.0[2] == "fields_relational" && tree.1[0] == "Many2many" ||
2591+
tree.0[2] == "fields_misc" && tree.1[0] == "Id"
2592+
){
2593+
cache.replace(true);
25952594
return true;
25962595
}
2596+
} else {
2597+
if tree.0.len() == 2 && tree.1.len() == 1 && tree.0[0] == "odoo" && tree.0[1] == "fields" {
2598+
if matches!(tree.1[0].as_str(), "Boolean" | "Integer" | "Float" | "Monetary" | "Char" | "Text" | "Html" | "Date" | "Datetime" |
2599+
"Binary" | "Image" | "Selection" | "Reference" | "Json" | "Properties" | "PropertiesDefinition" | "Id" | "Many2one" | "One2many" | "Many2many" | "Many2oneReference") {
2600+
cache.replace(true);
2601+
return true;
2602+
}
2603+
}
2604+
}
2605+
if self.is_inheriting_from_field(session) {
2606+
cache.replace(true);
2607+
return true;
25972608
}
25982609
}
2599-
if self.is_inheriting_from_field(session) {
2600-
return true;
2601-
}
2610+
cache.replace(false);
26022611
false
26032612
}
26042613

0 commit comments

Comments
 (0)