https://discord.cloudflare.com logo
Join Discord
Powered by
# durable-objects
  • d

    Dani Foldi

    03/29/2023, 10:06 AM
    even if the timezones of the user, the poll and whatever won't be the same, and you could be in an edge case where a submitted user date isn't in the same month as the storage date
  • c

    Crazy Rabbit

    03/29/2023, 10:07 AM
    So Date.now() is different based on where each edge is located?
  • c

    Crazy Rabbit

    03/29/2023, 10:10 AM
    So I should be storing:
    Copy code
    js
    new Date().toISOString()
  • d

    Dani Foldi

    03/29/2023, 10:13 AM
    Date.now()
    is fine, and so is
    new Date()
    - JS uses UTC timestamps internally. What I'm trying to say is that if you are located in a different timezone, and it is the 1st day of a month, just after midnight, your
    new Date()
    might still be in the last month
  • c

    Crazy Rabbit

    03/29/2023, 10:19 AM
    So the most reliable way would be to loop thru keys and delete old ones.
  • c

    Crazy Rabbit

    03/29/2023, 10:20 AM
    So basically I can do this every few weeks or months.
  • d

    Dani Foldi

    03/29/2023, 10:20 AM
    depending on how many votes you're expecting, you can calculate the optimal alarm call vs storage amount cost
  • d

    Dani Foldi

    03/29/2023, 10:21 AM
    I'd just leave the ones from the last day of the previous month in place, after 24 hours you should be safe to delete
  • c

    Crazy Rabbit

    03/29/2023, 10:23 AM
    Thanks
  • c

    Crazy Rabbit

    03/29/2023, 10:25 AM
    For votes probably maximum 200 000 per poll per month.
  • c

    Crazy Rabbit

    03/29/2023, 10:25 AM
    and each vote will store date in milliseconds + IP
  • c

    Crazy Rabbit

    03/29/2023, 10:26 AM
    so 2 keys per vote
  • c

    Crazy Rabbit

    03/29/2023, 10:28 AM
    That's why it would be a lot easier to just delete everything at the end of the month, but it won't be reliable as they could vote again at that time.
  • c

    Crazy Rabbit

    03/29/2023, 10:49 AM
    When someone vote I'm increasing votes and votes_total columns in D1.
  • c

    Crazy Rabbit

    03/29/2023, 10:50 AM
    If DOs are faster, I can also move those to DOs.
  • c

    Crazy Rabbit

    03/29/2023, 10:51 AM
    But I also don't store who voted. DO will just prevent the same username and the same IP to vote again in the same day.
  • c

    Crazy Rabbit

    03/29/2023, 10:52 AM
    So I can also start logging usernames in DOs and how many votes they made per month.
  • s

    Slin

    03/29/2023, 11:36 AM
    When using list, can I use the end and limit options to get the previous limit number of results? Or will it just return results from the start, but less then limit if it encounters the end key?
  • c

    ckoeninger

    03/29/2023, 2:32 PM
    The paragraph that HardAtWork linked you to links to https://blog.cloudflare.com/durable-objects-alarms/ which does have an example usage of alarms. For better or worse, a lot of cloudflare documentation, not just for DOs, links to blog posts for more detailed discussion / examples.
  • c

    Crazy Rabbit

    03/29/2023, 2:33 PM
    Thanks
  • c

    Crazy Rabbit

    03/29/2023, 2:34 PM
    Is:
    Copy code
    toml
    compatibility_flags = ["durable_object_alarms"]
    still needed?
  • c

    ckoeninger

    03/29/2023, 2:34 PM
    no
  • c

    Crazy Rabbit

    03/29/2023, 2:34 PM
    thanks
  • c

    Crazy Rabbit

    03/29/2023, 2:35 PM
    That's why I usually don't like blogs as most things are outdated-
  • c

    Crazy Rabbit

    03/29/2023, 2:35 PM
    docs seems to be up to date
  • d

    Dani Foldi

    03/29/2023, 2:57 PM
    If you check the docs on compatibility dates, it mentions the earliest date after which alarms are enabled by default
  • c

    Crazy Rabbit

    03/29/2023, 3:22 PM
    DO reads seems to be cheaper than KV reads, but I should probably still cache DO results to KV for faster access and to not put too much load on DO right?
  • z

    zegevlier

    03/29/2023, 3:24 PM
    DO reads are priced differently, you pay per 4kb (iirc) segment instead of per object read.
  • h

    HardAtWork

    03/29/2023, 3:28 PM
    DO reads are definitely faster than KV reads
  • h

    HardAtWork

    03/29/2023, 3:28 PM
    Especially since a read can be in memory
1...528529530...567Latest