Skip to content

Commit

Permalink
fix: Using safeArrayPush(dest, source) instead of `dest.push(...sou…
Browse files Browse the repository at this point in the history
…rce)` (#506) (#507)

Co-authored-by: Anton Prokopenko <a.prokopenko@crpt.ru>
  • Loading branch information
BanderasPRO and Anton Prokopenko authored Oct 5, 2023
1 parent 13ef4c4 commit 1295cec
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/orama/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,9 @@ export async function searchByWhereClause<T extends AnyOrama, ResultDocument = T

if (type === 'Flat') {
if (isArray) {
filtersMap[param].push(...flatFilterArr(node, operation as EnumArrComparisonOperator))
safeArrayPush(filtersMap[param], flatFilterArr(node, operation as EnumArrComparisonOperator))
} else {
filtersMap[param].push(...flatFilter(node, operation as EnumComparisonOperator))
safeArrayPush(filtersMap[param], flatFilter(node, operation as EnumComparisonOperator))
}
continue
}
Expand Down
3 changes: 2 additions & 1 deletion packages/orama/src/components/sorter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
InternalDocumentIDStore,
getInternalDocumentId,
} from './internal-document-id-store.js';
import { safeArrayPush } from "../utils.js";

interface PropertySort<K> {
docs: Map<InternalDocumentID, number>
Expand Down Expand Up @@ -56,7 +57,7 @@ function innerCreate<T extends AnyOrama>(
if (typeof type === 'object' && !Array.isArray(type)) {
// Nested
const ret = innerCreate(orama, sharedInternalDocumentStore, type, sortableDeniedProperties, path)
sorter.sortableProperties.push(...ret.sortableProperties)
safeArrayPush(sorter.sortableProperties, ret.sortableProperties);
sorter.sorts = {
...sorter.sorts,
...ret.sorts,
Expand Down
6 changes: 3 additions & 3 deletions packages/orama/src/trees/flat.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { InternalDocumentID } from "../components/internal-document-id-store.js"
import { EnumArrComparisonOperator, EnumComparisonOperator, Nullable, ScalarSearchableValue } from "../types.js"
import { intersect } from "../utils.js"
import { intersect, safeArrayPush } from "../utils.js"

export interface FlatTree {
numberToDocumentId: Map<ScalarSearchableValue, InternalDocumentID[]>
Expand Down Expand Up @@ -69,7 +69,7 @@ export function filter(root: FlatTree, operation: EnumComparisonOperator): Inter
for (const v of value) {
const ids = root.numberToDocumentId.get(v)
if (ids) {
result.push(...ids)
safeArrayPush(result, ids)
}
}
return result
Expand All @@ -85,7 +85,7 @@ export function filter(root: FlatTree, operation: EnumComparisonOperator): Inter
}
const ids = root.numberToDocumentId.get(key)
if (ids) {
result.push(...ids)
safeArrayPush(result, ids)
}
}
return result
Expand Down

1 comment on commit 1295cec

@vercel
Copy link

@vercel vercel bot commented on 1295cec Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.