Skip to content

Commit 8518894

Browse files
committed
WIP Stat Tracking changes.
1 parent e22d524 commit 8518894

File tree

2 files changed

+7
-19
lines changed

2 files changed

+7
-19
lines changed

lib/src/functions/functions_repository.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,12 @@ class FunctionsRepository {
6767
_log('Performing action: $action');
6868

6969
final Codelessly codelessly = context.read<Codelessly>();
70-
codelessly.tracker.trackAction(action);
70+
switch (action.type) {
71+
case ActionType.loadFromCloudStorage || ActionType.setCloudStorage:
72+
codelessly.tracker.trackCloudAction(action);
73+
default:
74+
codelessly.tracker.trackAction(action);
75+
}
7176

7277
switch (action.type) {
7378
case ActionType.navigation:

lib/src/logging/stat_tracker.dart

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'package:cloud_firestore/cloud_firestore.dart';
21
import 'package:codelessly_api/codelessly_api.dart';
32

43
import '../constants.dart';
@@ -35,10 +34,6 @@ abstract class StatTracker {
3534
/// A [StatTracker] implementation that utilizes Firestore to track the
3635
/// statistics.
3736
final class FirestoreStatTracker extends StatTracker {
38-
/// The Firestore document reference to track the statistics.
39-
DocumentReference get ref => FirebaseFirestore.instance
40-
.collection(statsCollection)
41-
.doc(projectId ?? lostStatsDoc);
4237

4338
/// The field name to track the number of each operation.
4439
final Map<String, int> statBatch = {};
@@ -50,19 +45,7 @@ final class FirestoreStatTracker extends StatTracker {
5045
/// Sends the batch of stats to the Firestore.
5146
Future<void> sendBatch() => debouncer.run(
5247
() async {
53-
// No need to await it. Send it and immediately start collecting more
54-
// stats.
55-
ref.set(
56-
{
57-
for (final entry in statBatch.entries)
58-
entry.key: FieldValue.increment(entry.value),
59-
60-
// Account for this stat tracking operation as an additional write
61-
// operation.
62-
'$writesField/stats': FieldValue.increment(1),
63-
},
64-
SetOptions(merge: true),
65-
);
48+
// TODO: call api endpoint.
6649
statBatch.clear();
6750
},
6851
forceRunAfter: 20,

0 commit comments

Comments
 (0)