fix: on analytics DB init, don't clear DB unless stored userID doesn't match client userID (#5036)
This commit is contained in:
parent
bd58baee04
commit
a322cb5ad2
2 changed files with 17 additions and 2 deletions
|
|
@ -120,7 +120,11 @@ class AnalyticsDataService {
|
|||
}
|
||||
|
||||
_invalidateCaches();
|
||||
await _clearDatabase();
|
||||
final analyticsUserId = await _analyticsClientGetter.database.getUserID();
|
||||
if (analyticsUserId != client.userID) {
|
||||
await _clearDatabase();
|
||||
await _analyticsClientGetter.database.updateUserID(client.userID!);
|
||||
}
|
||||
|
||||
final resp = await client.getUserProfile(client.userID!);
|
||||
final analyticsProfile =
|
||||
|
|
@ -367,7 +371,7 @@ class AnalyticsDataService {
|
|||
final newConstructs = await getConstructUses(updateIds);
|
||||
|
||||
int points = 0;
|
||||
if (blocked.isEmpty || updateIds.isNotEmpty) {
|
||||
if (update.blockedConstruct == null || updateIds.isNotEmpty) {
|
||||
for (final id in updateIds) {
|
||||
final prevPoints = prevConstructs[id]?.points ?? 0;
|
||||
final newPoints = newConstructs[id]?.points ?? 0;
|
||||
|
|
|
|||
|
|
@ -175,6 +175,8 @@ class AnalyticsDatabase with DatabaseFileStorage {
|
|||
(ConstructTypeEnum.morph, false) => _aggregatedServerMorphConstructsBox,
|
||||
};
|
||||
|
||||
Future<String?> getUserID() => _lastEventTimestampBox.get('user_id');
|
||||
|
||||
Future<DateTime?> getLastEventTimestamp() async {
|
||||
final timestampString =
|
||||
await _lastEventTimestampBox.get('last_event_timestamp');
|
||||
|
|
@ -482,6 +484,15 @@ class AnalyticsDatabase with DatabaseFileStorage {
|
|||
return combined.values.toList();
|
||||
}
|
||||
|
||||
Future<void> updateUserID(String userID) {
|
||||
return _transaction(() async {
|
||||
await _lastEventTimestampBox.put(
|
||||
'user_id',
|
||||
userID,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> updateXPOffset(int offset) {
|
||||
return _transaction(() async {
|
||||
final stats = await getDerivedStats();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue