Skip to content

Commit 649cfc7

Browse files
committed
slight efficiency to showRowsByKeyVals
1 parent a14a9c2 commit 649cfc7

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

lib/DataHarmonizer.js

+18-19
Original file line numberDiff line numberDiff line change
@@ -754,17 +754,13 @@ class DataHarmonizer {
754754
afterSelection: (row, column, row2, column2) => {
755755
// A change in selected row
756756
if (self.current_selection[0] != row) {
757-
// Possibly focused key has changed child table's filter.
758-
// Issue: need to cascade this down immediately to any
759-
// subordinate table, otherwise if doing on-demand from a table's
760-
// perspective, then if such a table depends on an intermediate that
761-
// hasn't been refreshed, we'll get a wrong display.
762-
757+
// Row has changed so possibly values that make up some other
758+
// table's foreign key has changed, so that table's view should
759+
// be refreshed.
763760
Object.entries(this.context.getDependents(this.template_name))
764761
.forEach(([child_name, child]) => {
765762
// Dependent tables determine what parent foreign key values they
766763
// need to filter view by
767-
console.log("showing", child_name)
768764
this.showRowsByKeyVals(child_name);
769765
});
770766
};
@@ -881,12 +877,11 @@ class DataHarmonizer {
881877
}
882878

883879

884-
885-
// Here we deal with adding rows that need foreign keys.
886-
// Locate each foreign key and fetch its focused value, and copy into new
887-
// records below.
888-
// If missing key value(s), prompt user to focus appropriate tab(s) row
889-
// and try again.
880+
/* Here we deal with adding rows that need foreign keys. Locate each foreign
881+
* key and fetch its focused value, and copy into new records below.
882+
* If missing key value(s) encountered, prompt user to focus appropriate
883+
* tab(s) row and try again.
884+
*/
890885
getForeignKeyValues(parents) {
891886
let required_selections = {};
892887
let errors = '';
@@ -1088,32 +1083,36 @@ class DataHarmonizer {
10881083
}
10891084

10901085
/* For given template name, show only rows that conform to that class's
1091-
* foreign key-value constraints;
1086+
* foreign key-value constraints.
1087+
* (Could make a touch more efficient by skipping if we can tell that a
1088+
* given table's foreign key values haven't changed.)
10921089
*/
10931090
showRowsByKeyVals(template_name) {
10941091
const hotInstance = this.context.dhs[template_name].hot;
10951092
const hiddenRowsPlugin = hotInstance.getPlugin('hiddenRows');
10961093

10971094
// Ensure all rows are visible
1098-
hiddenRowsPlugin.showRows(hiddenRowsPlugin.getHiddenRows());
1095+
let oldHiddenRows = hiddenRowsPlugin.getHiddenRows()
10991096

11001097
//Fetch key-values to match
11011098
let parents = this.context.getParents(template_name);
11021099
let [required_selections, errors] = this.getForeignKeyValues(parents);
11031100
// arrayRange() makes [0, ... n]
1104-
let rowsToHide = arrayRange(0,hotInstance.countRows())
1101+
let rowsToHide = arrayRange(0, hotInstance.countRows())
11051102
.filter((row) => {
11061103
for (let [slot_name, value] of Object.entries(required_selections)) {
11071104
const col = this.context.dhs[template_name].getColumnIndexByFieldName(slot_name);
11081105
const cellValue = hotInstance.getDataAtCell(row, col);
1109-
console.log(template_name,row,slot_name, col,cellValue,value)
11101106
if (cellValue != value)
11111107
return true;
11121108
}
11131109
});
11141110

1115-
hiddenRowsPlugin.hideRows(rowsToHide); // Hide the calculated rows
1116-
hotInstance.render(); // Render the table to apply changes
1111+
if (rowsToHide != oldHiddenRows) {
1112+
hiddenRowsPlugin.showRows(oldHiddenRows);
1113+
hiddenRowsPlugin.hideRows(rowsToHide); // Hide the calculated rows
1114+
hotInstance.render(); // Render the table to apply changes
1115+
}
11171116
}
11181117

11191118
renderSemanticID(curieOrURI, as_markup = false) {

0 commit comments

Comments
 (0)