Skip to content

Commit

Permalink
fromDbFast
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars-Erik Roald committed Jun 23, 2024
1 parent 37cbfc3 commit 70de078
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "orange-orm",
"version": "4.2.0-beta.3",
"version": "4.2.0-beta.4",
"main": "./src/index.js",
"browser": "./src/client/index.mjs",
"bin": {
Expand Down
18 changes: 9 additions & 9 deletions src/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ function rdbClient(options = {}) {
let args = [_, strategy].concat(Array.prototype.slice.call(arguments).slice(2));
let rows = await getManyCore.apply(null, args);
await metaPromise;
return proxify(rows, strategy, {fast: true});
return proxify(rows, strategy, true);
}

async function groupBy(strategy) {
Expand Down Expand Up @@ -261,7 +261,7 @@ function rdbClient(options = {}) {
await metaPromise;
if (rows.length === 0)
return;
return proxify(rows[0], strategy, {fast: true});
return proxify(rows[0], strategy, true);
}

async function getById() {
Expand Down Expand Up @@ -449,14 +449,14 @@ function rdbClient(options = {}) {
}


function proxify(itemOrArray, strategy, options) {
function proxify(itemOrArray, strategy, fast) {
if (Array.isArray(itemOrArray))
return proxifyArray(itemOrArray, strategy, options);
return proxifyArray(itemOrArray, strategy, fast);
else
return proxifyRow(itemOrArray, strategy, options);
return proxifyRow(itemOrArray, strategy, fast);
}

function proxifyArray(array, strategy, { fast } = { }) {
function proxifyArray(array, strategy, fast) {
let _array = array;
if (_reactive)
array = _reactive(array);
Expand Down Expand Up @@ -485,15 +485,15 @@ function rdbClient(options = {}) {
};
let innerProxy = new Proxy(array, handler);
//todo
rootMap.set(array, { json: fast ? structuredClone(array) : cloneFromDb(array), strategy, originalArray: [...array] });
rootMap.set(array, { json: cloneFromDb(array, fast), strategy, originalArray: [...array] });
if (strategy !== undefined) {
const { limit, ...cleanStrategy } = { ...strategy };
fetchingStrategyMap.set(array, cleanStrategy);
}
return innerProxy;
}

function proxifyRow(row, strategy, { fast } = {}) {
function proxifyRow(row, strategy, fast) {
let handler = {
get(_target, property,) {
if (property === 'save' || property === 'saveChanges') //call server then acceptChanges
Expand All @@ -518,7 +518,7 @@ function rdbClient(options = {}) {

};
let innerProxy = new Proxy(row, handler);
rootMap.set(row, { json: fast ? structuredClone(row) : cloneFromDb(row), strategy });
rootMap.set(row, { json: cloneFromDb(row, fast), strategy });
fetchingStrategyMap.set(row, strategy);
return innerProxy;
}
Expand Down

0 comments on commit 70de078

Please sign in to comment.