-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ios): add session sampling and data cleanup
- Loading branch information
Adwin Ronald Ross
committed
Jan 16, 2025
1 parent
9b46c98
commit 0887025
Showing
30 changed files
with
414 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// DataCleanupService.swift | ||
// MeasureSDK | ||
// | ||
// Created by Adwin Ross on 14/01/25. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol DataCleanupService { | ||
func clearStaleData() | ||
} | ||
|
||
final class BaseDataCleanupService: DataCleanupService { | ||
private let eventStore: EventStore | ||
private let sessionStore: SessionStore | ||
private let logger: Logger | ||
private let sessionManager: SessionManager | ||
|
||
init(eventStore: EventStore, sessionStore: SessionStore, logger: Logger, sessionManager: SessionManager) { | ||
self.eventStore = eventStore | ||
self.sessionStore = sessionStore | ||
self.logger = logger | ||
self.sessionManager = sessionManager | ||
} | ||
|
||
func clearStaleData() { | ||
guard let sessionsToDelete = getSessionsToDelete() else { | ||
logger.internalLog(level: .info, message: "No session data to clear.", error: nil, data: nil) | ||
return | ||
} | ||
|
||
sessionStore.deleteSessions(sessionsToDelete) | ||
eventStore.deleteEvents(sessionIds: sessionsToDelete) | ||
} | ||
|
||
private func getSessionsToDelete() -> [String]? { | ||
guard var sessionsToDelete = sessionStore.getSessionsToDelete() else { | ||
return nil | ||
} | ||
|
||
sessionsToDelete.removeAll { $0 == sessionManager.sessionId } | ||
|
||
return sessionsToDelete | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.