Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/dart/lib/src/network/parse_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ abstract class ParseClient {
}
String? installationId;
try {
installationId =
(await ParseInstallation.currentInstallation()).installationId;
// Cached after first call — the install ID is immutable per device, so
// we avoid hitting the local store + JSON-decoding the full installation
// on every HTTP request.
installationId = await ParseInstallation.currentInstallationId();
} catch (_) {
return options?.headers;
}
Expand Down
19 changes: 19 additions & 0 deletions packages/dart/lib/src/objects/parse_installation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,25 @@ class ParseInstallation extends ParseObject {
return (await _getFromLocalStore()) ?? (await _createInstallation());
}

/// Returns the current installation's UUID without parsing the full
/// installation document. Caches the value in [_currentInstallationId] after
/// the first resolution so hot paths (e.g. `ParseClient.buildHeaders`, which
/// runs on every HTTP request) don't repeatedly hit the local store and
/// re-decode JSON. The install ID is immutable for the lifetime of the app
/// on a given device, so the cache never needs invalidation.
static Future<String?> currentInstallationId() async {
if (_currentInstallationId != null) return _currentInstallationId;
final ParseInstallation? stored = await _getFromLocalStore();
if (stored?.installationId != null) {
_currentInstallationId = stored!.installationId;
return _currentInstallationId;
}
// No installation yet — create one. `_createInstallation` populates
// `_currentInstallationId` as part of its work.
await _createInstallation();
return _currentInstallationId;
Comment thread
AdrianCurtin marked this conversation as resolved.
Outdated
}
Comment thread
AdrianCurtin marked this conversation as resolved.
Outdated

/// Updates the installation with current device data
Future<void> _updateInstallation() async {
//Device type
Expand Down
Loading