MCPcopy Create free account
hub / github.com/OpenWebCAD/node-occ / __performedCachedOperation

Method __performedCachedOperation

lib/fastbuilder.js:107–181  ·  view source on GitHub ↗
(originalObject, originalMethod, methodName, theArguments, callAsConstructor)

Source from the content-addressed store, hash-verified

105 }
106
107 __performedCachedOperation(originalObject, originalMethod, methodName, theArguments, callAsConstructor) {
108
109 assert(theArguments.hasOwnProperty("length"));
110
111 const h = calculateOperationHash(methodName, theArguments, callAsConstructor);
112 const uuid = h[0];
113 const cmd = h[1];
114
115 debugLog(" executing method ", cmd, uuid);
116
117 // check if object is already known
118 this.mapQueryCount++;
119 if (this.mapObject.hasOwnProperty(uuid)) {
120
121 const obj = this.mapObject[uuid];
122 assert(obj.uuid === uuid, " checking object uuid consistency");
123 debugLog(" using object from cache ", obj.uuid, obj.cmd);
124
125 this.mapHit++;
126 return obj;
127
128 }
129
130 // otherwise perform the "costly" original operation
131 let result;
132 try {
133
134 if (callAsConstructor) {
135
136 // New object must be unique....
137 assert(false);
138 const args = [null].concat(Object.keys(theArguments).map(f => theArguments[f]));
139 const FactoryFunction = originalMethod.bind(...args);
140 result = new FactoryFunction();
141
142 } else {
143
144 const args = Object.keys(theArguments).map(f => theArguments[f]);
145 result = originalMethod.apply(originalObject, args);
146
147 }
148
149 } catch (err) {
150
151 debugLog(` FAILING to call ${methodName}(`, `${Object.keys(theArguments).map(e => JSON.stringify(theArguments[e])).join(" , ")})`);
152
153 throw err; // re-throw execption above
154
155 }
156
157 const _this = this;
158
159 if (result instanceof Array) {
160
161 debugLog("result is an array with ", result.length, " elements");
162
163
164 result.forEach((el, index) => {

Callers 2

__proxyMethod · 0.95
performOperationMethod · 0.80

Calls 3

prepareObjectMethod · 0.80
calculateOperationHashFunction · 0.70
debugLogFunction · 0.70

Tested by

no test coverage detected