mesqueeb / vuex-easy-firestore

Easy coupling of firestore and a vuex module. 2-way sync with 0 boilerplate!
https://mesqueeb.github.io/vuex-easy-firestore
MIT License
234 stars 28 forks source link

Write Rate Limiting - Best Practices? #345

Closed danmalone89 closed 4 years ago

danmalone89 commented 4 years ago

I've implemented some rate limiting in my firestore rules (using duration), and have been experimenting with rate limiting using this package's hooks on the client side. The function below compares the current time, against the last time a post was written to the db (represented in a field in a document). I consider my firestore rules as my backup rate limiter.

What are y'all doing to solve rate limiting on the client or with firestore rules?

  sync: {
    insertHook: function(updateStore, doc, store) {
      const x = dayjs(); // current time
      const y = dayjs.unix(store.getters["userData/lastPostTime"].seconds); // Unix to Local Time (yes, VEF could do this for me)
      const duration = x.diff(y, "second", true);
      duration > 10 // seconds 
        ? updateStore(doc)
        : alert("Your doing that too much.");
    },
  },