You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a collection that requires filtering on multiple fields (e.g. startDate + endDate + accountId). I have indexed each of these fields but am seeing a performance hit whenever I try to filter on more than one field. Is there a way to create a compound index in Swift (e.g. an index that includes multiple properties)? Are there any best practices for creating performant queries when filtering on multiple properties?
Here is an example of what I'm trying to do:
class Event: Object { @persisted var id: String // Primary key @persisted(indexed: true) var accountId: Int // Each account has its own events @persisted(indexed: true) var startedAt: Date // Events can be filtered by date @persisted(indexed: true) var eventType: String // Events can be filtered by type @persisted var notes: String
For a collection with 20K objects, performance is acceptable as l filter on only startedAt and EndedAt. As soon as I add the filter for accountId, performance degrades drastically. The order of the filters doesn't seem to matter
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a collection that requires filtering on multiple fields (e.g. startDate + endDate + accountId). I have indexed each of these fields but am seeing a performance hit whenever I try to filter on more than one field. Is there a way to create a compound index in Swift (e.g. an index that includes multiple properties)? Are there any best practices for creating performant queries when filtering on multiple properties?
Here is an example of what I'm trying to do:
class Event: Object {
@persisted var id: String // Primary key
@persisted(indexed: true) var accountId: Int // Each account has its own events
@persisted(indexed: true) var startedAt: Date // Events can be filtered by date
@persisted(indexed: true) var eventType: String // Events can be filtered by type
@persisted var notes: String
}
For a collection with 20K objects, performance is acceptable as l filter on only startedAt and EndedAt. As soon as I add the filter for accountId, performance degrades drastically. The order of the filters doesn't seem to matter
Beta Was this translation helpful? Give feedback.
All reactions