You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: firestore-counter/POSTINSTALL.md
+46-44Lines changed: 46 additions & 44 deletions
Original file line number
Diff line number
Diff line change
@@ -4,28 +4,29 @@ Before you can use this extension, you'll need to update your security rules, se
4
4
5
5
#### Update security rules
6
6
7
-
Update your Cloud Firestore security rules to allow lookups and writes to the `_counter_shards_` subcollection where you want the extension to count. For example, to allow clients to increment the `visits` field on any document in the `pages` collection, you can write rules like this:
7
+
Update your Cloud Firestore security rules to allow reads and writes to the `_counter_shards_` subcollection where you want the extension to count, for example:
8
8
9
9
```
10
10
match /databases/{database}/documents/pages/{page} {
11
-
// Allow to increment only the 'visits' field and only by 1.
11
+
// Allow to increment only 'visits' field and only by 1.
12
12
match /_counter_shards_/{shardId} {
13
-
allow get;
14
-
allow write: if request.resource.data.keys() == ["visits"]
Review the [scheduled function documentation](https://firebase.google.com/docs/functions/schedule-functions) to set up a call to `${function:controller.url}` every minute. You may need to enable some APIs in your Firebase project to use scheduled functions.
25
+
Set up a [scheduled function](https://firebase.google.com/docs/functions/schedule-functions) to call `${function:controller.url}` every minute.
24
26
25
-
As an example, to set up a scheduled function, you can run the following [`gcloud`](https://cloud.google.com/sdk/gcloud/)commands:
27
+
For example, to set up a scheduled function, you can run the following [`gcloud`](https://cloud.google.com/sdk/gcloud/)command:
Note: You might get a "Permission denied" error for the source repository. If you do, locate the **Sign in** button on the error page, then sign in to access to the repo.
37
38
38
-
1. Use the Counter SDK library in your code to increment counters. The code snippet below shows an example of how to use the library. For more comprehensive API documentation, refer to the [source code](https://dev-partners.googlesource.com/samples/firebase/mods/+/master/firestore-counter/clients/web/src/index.ts).
Copy file name to clipboardExpand all lines: firestore-counter/PREINSTALL.md
+2-14Lines changed: 2 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,8 @@
1
1
Use this extension to add a highly scalable counter service to your app. This is ideal for applications that count viral actions or any very high-velocity action such as views, likes, or shares.
2
2
3
-
Cloud Firestore has a limit of 1 sustained write per second, per document. This limit can make counting in Cloud Firestore challenging.
4
-
This extension works around the concurrent document writes per second limitation and lets your app update any field in any document of your Cloud Firestore database at a high rate (security rules permitting). It accomplishes this by using numerous temporary shards in a `_counter_shards_` subcollection; allowing it to sustain high bursts of traffic. Each client only increments their own unique shard while the background workers (Cloud Functions for Firebase) continue to monitor and aggregate these shards onto the master document.
3
+
In your app, you specify a Cloud Firestore document path and increment a field value by any amount you choose. The extension then creates a subcollection in that document to help track the counter in a scalable way.
5
4
6
-
Here are some of the important features of this extension:
7
-
8
-
- Minimal configuration, one extension for all your app needs.
9
-
- Automatically scales from 0 updates per second to at least 10 thousand per second.
10
-
- Supports an arbitrary number of counters in your app with no additional configuration.
11
-
- Works well offline and provides latency compensation, i.e. counter updates are immediately visible locally even though the main counter is eventually updated.
12
-
- Resource efficient.
13
-
-`worker` functions will scale down to 0 for low workloads if needed.
14
-
-`onWrite` function is [limted to 1 instance](https://cloud.google.com/functions/docs/max-instances#using_max_instances).
15
-
-`controller` is the only function that runs every minute regardless of the workload.
16
-
17
-
This mod can work on any platform. However there's only [JavaScript SDK](https://dev-partners.googlesource.com/samples/firebase/mods/+/master/firestore-sharded-counter/clients/web/src/index.ts) included at this time. This will change in the future.
5
+
Note that this extension is for use with the JavaScript apps and requires the Firebase JavaScript SDK.
0 commit comments