Skip to content

Commit

Permalink
Minor improvement:
Browse files Browse the repository at this point in the history
executionStrategy.Both inlineCount calculation improvement; queries with groupBy excluded this calculation, because we can never know the effect of the added and deleted entities to result inline count.
  • Loading branch information
umutozel committed Aug 21, 2014
1 parent d38031d commit fbeb4a9
Show file tree
Hide file tree
Showing 16 changed files with 136 additions and 69 deletions.
Binary file modified Beetle.Client/App_Data/Test.sdf
Binary file not shown.
38 changes: 26 additions & 12 deletions Beetle.Client/Scripts/beetle/beetle.js
Original file line number Diff line number Diff line change
Expand Up @@ -5507,7 +5507,7 @@

return new ctor();
})();

/// <field>Returns second of date</field>
expose.second = (function () {
var ctor = function () {
Expand Down Expand Up @@ -8393,7 +8393,7 @@

// execute locally if needed.
if (execution == enums.executionStrategy.Local || execution == enums.executionStrategy.LocalIfEmptyServer)
locals = this.executeQueryLocally(query);
locals = this.executeQueryLocally(query, options && options.varContext);

var retVal = null;
// if there is no need for server query, return
Expand Down Expand Up @@ -8422,9 +8422,11 @@
}
// if option need local and server results both, after server query re-run same query on local.
if (execution == enums.executionStrategy.Both) {
newEntities = that.executeQueryLocally(query);
if (inlineCount)
inlineCount += newEntities.$addedCount - newEntities.$deletedCount;
newEntities = that.executeQueryLocally(query, options && options.varContext, true);
if (inlineCount && newEntities.$inlineCountDiff) {
inlineCount += newEntities.$inlineCountDiff;
delete newEntities.$inlineCountDiff;
}
}
if (newEntities) {
if (query.inlineCountEnabled && inlineCount != null)
Expand All @@ -8450,7 +8452,7 @@
return retVal;
};

proto.executeQueryLocally = function (query, varContext) {
proto.executeQueryLocally = function (query, varContext, calculateInlineCountDiff) {
/// <summary>
/// Execute the query.
/// </summary>
Expand All @@ -8470,23 +8472,34 @@
} else
throw helper.createError(i18N.typeRequiredForLocalQueries);

var array = [], addedCount = 0, deletedCount = 0;
if (calculateInlineCountDiff && query.getExpression(querying.expressions.groupByExp, false)) {
events.warning.notify({ message: i18N.countDiffCantBeCalculatedForGrouped, query: query, options: options });
calculateInlineCountDiff = false;
}

var array = [], addeds = [], deleteds = [];
helper.forEach(entities, function (entity) {
if (entity.$tracker.entityState == enums.entityStates.Added) {
addedCount++;
if (calculateInlineCountDiff)
addeds.push(entity);
array.push(entity);
}
else if (entity.$tracker.entityState == enums.entityStates.Deleted)
deletedCount++;
else if (entity.$tracker.entityState == enums.entityStates.Deleted) {
if (calculateInlineCountDiff)
deleteds.push(entity);
}
else
array.push(entity);
});
// get array handling function for query
var func = query.toFunction();
// run function against entities
array = func(array, varContext);
array.$addedCount = addedCount;
array.$deletedCount = deletedCount;
if (calculateInlineCountDiff && array.$inlineCount) {
var addedEffect = addeds.length > 0 ? func(addeds, varContext).$inlineCount : 0;
var deletedEffect = deleteds.length > 0 ? func(deleteds, varContext).$inlineCount : 0;
array.$inlineCountDiff = addedEffect - deletedEffect;
}
return array;
};

Expand Down Expand Up @@ -10159,6 +10172,7 @@
couldNotLocateNavFixer: 'Could not locate any observable provider.',
couldNotLocatePromiseProvider: 'Could not locate any promise provider.',
couldNotParseToken: 'Could not parse %0.',
countDiffCantBeCalculatedForGrouped: 'In-line count difference can not be calculated when query contains a "groupBy" expression',
dataPropertyAlreadyExists: 'Data property already exists: %0.',
entityAlreadyBeingTracked: 'Entity is already being tracked by another manager.',
entityNotBeingTracked: 'Entity is not being tracked by a manager.',
Expand Down
1 change: 1 addition & 0 deletions Beetle.Client/Scripts/beetle/beetle.lang-tr-TR.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
couldNotLocateNavFixer: 'Observable provider bulunamadı.',
couldNotLocatePromiseProvider: 'Promise provider bulunamadı.',
couldNotParseToken: '%0 yorumlanamadı.',
countDiffCantBeCalculatedForGrouped: 'İç-satır sayısı farkı "groupBy" ifadesi içeren sorgular için hesaplanamaz.',
dataPropertyAlreadyExists: 'Bu alan zaten eklenmiş: %0.',
entityAlreadyBeingTracked: 'Bu varlık zaten başka bir yönetici tarafından takip ediliyor.',
entityNotBeingTracked: 'Varlık bir yönetici tarafından takip edilmiyor.',
Expand Down
2 changes: 1 addition & 1 deletion Beetle.Client/Scripts/beetle/beetle.min.js

Large diffs are not rendered by default.

38 changes: 25 additions & 13 deletions Samples/Beetle.Samples.Northwind/Scripts/beetle.js
Original file line number Diff line number Diff line change
Expand Up @@ -5447,7 +5447,7 @@
}
return false;
}
return items && items.indexOf(item) > 0;
return items && items.indexOf(item) >= 0;
};

return new ctor();
Expand Down Expand Up @@ -5507,7 +5507,7 @@

return new ctor();
})();

/// <field>Returns second of date</field>
expose.second = (function () {
var ctor = function () {
Expand Down Expand Up @@ -8393,7 +8393,7 @@

// execute locally if needed.
if (execution == enums.executionStrategy.Local || execution == enums.executionStrategy.LocalIfEmptyServer)
locals = this.executeQueryLocally(query);
locals = this.executeQueryLocally(query, options && options.varContext);

var retVal = null;
// if there is no need for server query, return
Expand Down Expand Up @@ -8422,9 +8422,9 @@
}
// if option need local and server results both, after server query re-run same query on local.
if (execution == enums.executionStrategy.Both) {
newEntities = that.executeQueryLocally(query);
if (inlineCount)
inlineCount += newEntities.$addedCount - newEntities.$deletedCount;
newEntities = that.executeQueryLocally(query, options && options.varContext, true);
if (inlineCount && newEntities.$inlineCountDiff)
inlineCount += newEntities.$inlineCountDiff;
}
if (newEntities) {
if (query.inlineCountEnabled && inlineCount != null)
Expand All @@ -8450,7 +8450,7 @@
return retVal;
};

proto.executeQueryLocally = function (query, varContext) {
proto.executeQueryLocally = function (query, varContext, calculateInlineCountDiff) {
/// <summary>
/// Execute the query.
/// </summary>
Expand All @@ -8470,23 +8470,34 @@
} else
throw helper.createError(i18N.typeRequiredForLocalQueries);

var array = [], addedCount = 0, deletedCount = 0;
if (calculateInlineCountDiff && query.getExpression(querying.expressions.groupByExp, false)) {
events.warning.notify({ message: i18N.countDiffCantBeCalculatedForGrouped, query: query, options: options });
calculateInlineCountDiff = false;
}

var array = [], addeds = [], deleteds = [];
helper.forEach(entities, function (entity) {
if (entity.$tracker.entityState == enums.entityStates.Added) {
addedCount++;
if (calculateInlineCountDiff)
addeds.push(entity);
array.push(entity);
}
else if (entity.$tracker.entityState == enums.entityStates.Deleted)
deletedCount++;
else if (entity.$tracker.entityState == enums.entityStates.Deleted) {
if (calculateInlineCountDiff)
deleteds.push(entity);
}
else
array.push(entity);
});
// get array handling function for query
var func = query.toFunction();
// run function against entities
array = func(array, varContext);
array.$addedCount = addedCount;
array.$deletedCount = deletedCount;
if (calculateInlineCountDiff && array.$inlineCount) {
var addedEffect = addeds.length > 0 ? func(addeds, varContext).$inlineCount : 0;
var deletedEffect = deleteds.length > 0 ? func(deleteds, varContext).$inlineCount : 0;
array.$inlineCountDiff = addedEffect - deletedEffect;
}
return array;
};

Expand Down Expand Up @@ -10159,6 +10170,7 @@
couldNotLocateNavFixer: 'Could not locate any observable provider.',
couldNotLocatePromiseProvider: 'Could not locate any promise provider.',
couldNotParseToken: 'Could not parse %0.',
countDiffCantBeCalculatedForGrouped: 'In-line count difference can not be calculated when query contains a "groupBy" expression',
dataPropertyAlreadyExists: 'Data property already exists: %0.',
entityAlreadyBeingTracked: 'Entity is already being tracked by another manager.',
entityNotBeingTracked: 'Entity is not being tracked by a manager.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
couldNotLocateNavFixer: 'Observable provider bulunamadı.',
couldNotLocatePromiseProvider: 'Promise provider bulunamadı.',
couldNotParseToken: '%0 yorumlanamadı.',
countDiffCantBeCalculatedForGrouped: 'İç-satır sayısı farkı "groupBy" ifadesi içeren sorgular için hesaplanamaz.',
dataPropertyAlreadyExists: 'Bu alan zaten eklenmiş: %0.',
entityAlreadyBeingTracked: 'Bu varlık zaten başka bir yönetici tarafından takip ediliyor.',
entityNotBeingTracked: 'Varlık bir yönetici tarafından takip edilmiyor.',
Expand Down
2 changes: 1 addition & 1 deletion Samples/Beetle.Samples.Northwind/Scripts/beetle.min.js

Large diffs are not rendered by default.

38 changes: 25 additions & 13 deletions Samples/Todo/Beetle.Samples.Todo.Angular/Scripts/beetle.js
Original file line number Diff line number Diff line change
Expand Up @@ -5447,7 +5447,7 @@
}
return false;
}
return items && items.indexOf(item) > 0;
return items && items.indexOf(item) >= 0;
};

return new ctor();
Expand Down Expand Up @@ -5507,7 +5507,7 @@

return new ctor();
})();

/// <field>Returns second of date</field>
expose.second = (function () {
var ctor = function () {
Expand Down Expand Up @@ -8393,7 +8393,7 @@

// execute locally if needed.
if (execution == enums.executionStrategy.Local || execution == enums.executionStrategy.LocalIfEmptyServer)
locals = this.executeQueryLocally(query);
locals = this.executeQueryLocally(query, options && options.varContext);

var retVal = null;
// if there is no need for server query, return
Expand Down Expand Up @@ -8422,9 +8422,9 @@
}
// if option need local and server results both, after server query re-run same query on local.
if (execution == enums.executionStrategy.Both) {
newEntities = that.executeQueryLocally(query);
if (inlineCount)
inlineCount += newEntities.$addedCount - newEntities.$deletedCount;
newEntities = that.executeQueryLocally(query, options && options.varContext, true);
if (inlineCount && newEntities.$inlineCountDiff)
inlineCount += newEntities.$inlineCountDiff;
}
if (newEntities) {
if (query.inlineCountEnabled && inlineCount != null)
Expand All @@ -8450,7 +8450,7 @@
return retVal;
};

proto.executeQueryLocally = function (query, varContext) {
proto.executeQueryLocally = function (query, varContext, calculateInlineCountDiff) {
/// <summary>
/// Execute the query.
/// </summary>
Expand All @@ -8470,23 +8470,34 @@
} else
throw helper.createError(i18N.typeRequiredForLocalQueries);

var array = [], addedCount = 0, deletedCount = 0;
if (calculateInlineCountDiff && query.getExpression(querying.expressions.groupByExp, false)) {
events.warning.notify({ message: i18N.countDiffCantBeCalculatedForGrouped, query: query, options: options });
calculateInlineCountDiff = false;
}

var array = [], addeds = [], deleteds = [];
helper.forEach(entities, function (entity) {
if (entity.$tracker.entityState == enums.entityStates.Added) {
addedCount++;
if (calculateInlineCountDiff)
addeds.push(entity);
array.push(entity);
}
else if (entity.$tracker.entityState == enums.entityStates.Deleted)
deletedCount++;
else if (entity.$tracker.entityState == enums.entityStates.Deleted) {
if (calculateInlineCountDiff)
deleteds.push(entity);
}
else
array.push(entity);
});
// get array handling function for query
var func = query.toFunction();
// run function against entities
array = func(array, varContext);
array.$addedCount = addedCount;
array.$deletedCount = deletedCount;
if (calculateInlineCountDiff && array.$inlineCount) {
var addedEffect = addeds.length > 0 ? func(addeds, varContext).$inlineCount : 0;
var deletedEffect = deleteds.length > 0 ? func(deleteds, varContext).$inlineCount : 0;
array.$inlineCountDiff = addedEffect - deletedEffect;
}
return array;
};

Expand Down Expand Up @@ -10159,6 +10170,7 @@
couldNotLocateNavFixer: 'Could not locate any observable provider.',
couldNotLocatePromiseProvider: 'Could not locate any promise provider.',
couldNotParseToken: 'Could not parse %0.',
countDiffCantBeCalculatedForGrouped: 'In-line count difference can not be calculated when query contains a "groupBy" expression',
dataPropertyAlreadyExists: 'Data property already exists: %0.',
entityAlreadyBeingTracked: 'Entity is already being tracked by another manager.',
entityNotBeingTracked: 'Entity is not being tracked by a manager.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
couldNotLocateNavFixer: 'Observable provider bulunamadı.',
couldNotLocatePromiseProvider: 'Promise provider bulunamadı.',
couldNotParseToken: '%0 yorumlanamadı.',
countDiffCantBeCalculatedForGrouped: 'İç-satır sayısı farkı "groupBy" ifadesi içeren sorgular için hesaplanamaz.',
dataPropertyAlreadyExists: 'Bu alan zaten eklenmiş: %0.',
entityAlreadyBeingTracked: 'Bu varlık zaten başka bir yönetici tarafından takip ediliyor.',
entityNotBeingTracked: 'Varlık bir yönetici tarafından takip edilmiyor.',
Expand Down

Large diffs are not rendered by default.

Loading

0 comments on commit fbeb4a9

Please sign in to comment.