TipKit stores all Event donations including their Date locally. I am wondering if it's still good practise to have an Event for a action that happens a lot of times in my app (the main feature), since Power-Users could get over a million triggers of this event. This would result into millions of entries, but I only need a rule counting if the count is higher then 3. Would it be smarter to think of a different approach for this use-case to save storage (and maybe query speed), or is it still advised to use Events for something like this?
Tip Event for high-occurrence Event
If you don't care about donating the event after the tip has been dismissed by the user, you can stop donating it once the tip status changes to invalidated. That way you won't be filling up the database with events that are no longer needed. Here's some sample code:
struct SampleEventRuleTip: Tip {
var title: Text {
Text("Sample event-based tip")
}
var rules: [Rule] {
#Rule(Self.didPerformEvent) {
$0.donations.count >= 3
}
}
static let didPerformEvent: Event = Event(id: "didPerformEvent")
}
struct ContentView: View {
private var sampleEventTip = SampleEventRuleTip()
var body: some View {
VStack {
Button(action: {
let isTipInvalidated: Bool = switch sampleEventTip.status {
case .invalidated(_): true
case _: false
}
if isTipInvalidated {
// Don't donate the event since the tip has already been dismissed by the user.
} else {
// Donate the event
SampleEventRuleTip.didPerformEvent.sendDonation()
}
}, label: {
Text("Donate Event")
})
}
}
}