Skip to content

Commit 3cc8ba2

Browse files
issue investigation & some minor fix ups that're not complete
1 parent e7337c8 commit 3cc8ba2

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

Magic.IndexedDb/wwwroot/magicLinqToIndexedDb.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,13 +265,12 @@ function runIndexedQuery(table, indexedConditions, queryAdditions = []) {
265265
switch (addition.additionFunction) {
266266
case QUERY_ADDITIONS.ORDER_BY:
267267
if (addition.property) {
268-
orderByProperty = addition.property;
268+
query = query.orderBy(addition.property);
269269
}
270270
break;
271271
case QUERY_ADDITIONS.ORDER_BY_DESCENDING:
272272
if (addition.property) {
273-
orderByProperty = addition.property;
274-
needsReverse = true;
273+
query = query.orderBy(addition.property).reverse();
275274
}
276275
break;
277276
case QUERY_ADDITIONS.SKIP:

Magic.IndexedDb/wwwroot/utilities/linqValidation.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ export function validateQueryAdditions(queryAdditions, indexCache) {
1212
const schema = indexCache;
1313
const primaryKeys = schema ? Array.from(schema.compoundKeys) : [];
1414

15-
for (const addition of queryAdditions) {
16-
let validCombos = QUERY_ADDITION_RULES[addition.additionFunction];
15+
for (let i = 0; i < queryAdditions.length; i++) {
16+
const addition = queryAdditions[i];
17+
const validCombos = QUERY_ADDITION_RULES[addition.additionFunction];
1718

1819
if (!validCombos) {
1920
console.error(`Unsupported query addition: ${addition.additionFunction}`);
@@ -26,20 +27,19 @@ export function validateQueryAdditions(queryAdditions, indexCache) {
2627
const isIndexed = schema?.indexes.has(addition.property) || primaryKeys.includes(addition.property);
2728
if (!isIndexed) {
2829
debugLog(`Query requires cursor: ORDER_BY on non-indexed property ${addition.property}`);
29-
requiresCursor = true; // Forces cursor usage
30+
requiresCursor = true;
3031
}
3132
}
3233

33-
// **If TAKE_LAST is used after ORDER_BY, allow it (when indexed)**
3434
if (addition.additionFunction === QUERY_ADDITIONS.TAKE_LAST) {
35-
let prevAddition = queryAdditions[queryAdditions.indexOf(addition) - 1];
35+
const prevAddition = queryAdditions[i - 1];
3636
if (!prevAddition || (prevAddition.additionFunction !== QUERY_ADDITIONS.ORDER_BY && prevAddition.additionFunction !== QUERY_ADDITIONS.ORDER_BY_DESCENDING)) {
3737
debugLog(`TAKE_LAST requires ORDER_BY but was not found before it.`);
38-
requiresCursor = true; // Force cursor if there's no ORDER_BY before it.
38+
requiresCursor = true;
3939
}
4040
}
4141

42-
// Check if the addition conflicts with previous additions
42+
// Check for conflicts with previously seen additions
4343
for (const seen of seenAdditions) {
4444
if (!validCombos.includes(seen)) {
4545
requiresCursor = true;
@@ -54,6 +54,7 @@ export function validateQueryAdditions(queryAdditions, indexCache) {
5454
}
5555

5656
export function validateQueryCombinations(nestedOrFilter) {
57+
5758
debugLog("Validating Query Combinations", { nestedOrFilter });
5859

5960
if (!nestedOrFilter || !Array.isArray(nestedOrFilter.orGroups)) {

0 commit comments

Comments
 (0)