Skip to content

Limit writes to session file #243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
Prev Previous commit
Next Next commit
Create sessionFile in constructor
  • Loading branch information
eliasyishak committed Feb 28, 2024
commit 3f7ee72d76a97e22ee6ce0656b13d5d1ac2b75ec
5 changes: 0 additions & 5 deletions pkgs/unified_analytics/lib/src/analytics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,6 @@ class AnalyticsImpl implements Analytics {
homeDirectory: homeDirectory,
fs: fs,
errorHandler: _errorHandler,
sessionFile: fs.file(p.join(
homeDirectory.path,
kDartToolDirectoryName,
kSessionFileName,
)),
);
userProperty = UserProperty(
session: _sessionHandler,
Expand Down
6 changes: 4 additions & 2 deletions pkgs/unified_analytics/lib/src/session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import 'package:clock/clock.dart';
import 'package:file/file.dart';
import 'package:path/path.dart' as p;

import 'constants.dart';
import 'error_handler.dart';
Expand All @@ -22,8 +23,9 @@ class Session {
required this.homeDirectory,
required this.fs,
required ErrorHandler errorHandler,
required this.sessionFile,
}) : _sessionId = DateTime.now().millisecondsSinceEpoch,
}) : sessionFile = fs.file(p.join(
homeDirectory.path, kDartToolDirectoryName, kSessionFileName)),
_sessionId = DateTime.now().millisecondsSinceEpoch,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like it's "solving" the problem of LateInitializationError by assigning the variable the wrong value. Or am I misunderstanding how this works?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're correct, this value is getting set when calling the constructor and it will eventually get replaced when we run Session.initialize. This just makes it so that we don't have to make the variable late.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's technically not an invalid session id since later on in the code, we could be setting the this value in the file because we need a new session id if the old one had 30 mins of inactivity

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could be setting the this value in the file because we need a new session id if the old one had 30 mins of inactivity

But if it has NOT been 30 minutes of inactivity, the correct session ID would be a different value, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's correct, we would have to decide if that is worth it to remove the late variable

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lemme take a look at this later today?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgtm, no rush

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from discussion, maybe we should just make _sessionId nullable, and allow sending a null session id. this would also help when sending errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep this makes sense with me, i also just confirmed that sending null for the session id is a valid json payload for GA4

_errorHandler = errorHandler;

/// This will use the data parsed from the
Expand Down