AshRateLimiter - warning that unrelated update actions cannot be done atomically

I'm playing around with AshRateLimiter and have something like this:
rate_limit do
hammer MyApp.Hammer

action :create_thread,
limit: 5,
per: :timer.hours(2),
key: fn
_changeset, %{actor: %{ip: ip}} ->
"thread:#{ip}:create"

_changeset, _context ->
"skip"
end
end
rate_limit do
hammer MyApp.Hammer

action :create_thread,
limit: 5,
per: :timer.hours(2),
key: fn
_changeset, %{actor: %{ip: ip}} ->
"thread:#{ip}:create"

_changeset, _context ->
"skip"
end
end
And I'm specially handling "skip" to not apply rate limiting in my Hammer module. That all works, but my update actions are now giving warnings, even though I didn't touch them:
update :bump_thread do
change atomic_update(:bumped_at, expr(now()))
change atomic_update(:reply_count, expr(reply_count + 1))
end
update :bump_thread do
change atomic_update(:bumped_at, expr(now()))
change atomic_update(:reply_count, expr(reply_count + 1))
end
warning: [MyApp.Forum.Post]
actions -> bump_thread:
`MyApp.Forum.Post.bump_thread` cannot be done atomically, because the changes `[AshRateLimiter.Change, AshRateLimiter.Change]` cannot be done atomically
warning: [MyApp.Forum.Post]
actions -> bump_thread:
`MyApp.Forum.Post.bump_thread` cannot be done atomically, because the changes `[AshRateLimiter.Change, AshRateLimiter.Change]` cannot be done atomically
Any ideas why? Thanks
6 Replies
ZachDaniel
ZachDaniel3mo ago
Read the update actions guide about atomic updates I think there might be room here for atomic safe before action hooks TBH @jart interesting thought here
pikdum
pikdumOP3mo ago
right but I'm not rate limiting any update actions at least not intentionally, lol
jart
jart3mo ago
yeah but the before action hook in the rate limited actions always has to fire to check if the action should be rate limited. This means that it can no longer be run atomically. It's fine, just disable the warning.
pikdum
pikdumOP3mo ago
I'm explaining things poorly The update action it's warning about doesn't have rate limiting Only a few create actions in the same resource do Don't want these update actions to not be atomic It seems like if you add rate limiting to any action, you can't have any non default atomic update actions in the same resource or something
jart
jart3mo ago
Oh. Yeah that’s not right. Please open an issue on the repo.
pikdum
pikdumOP3mo ago
https://github.com/ash-project/ash_rate_limiter/issues/38 put together this, let me know if there's anything missing
GitHub
Non rate-limited update actions cannot be done atomically · Issue ...
Code of Conduct I agree to follow this project's Code of Conduct AI Policy I agree to follow this project's AI Policy, or I agree that AI was not used while creating this issue. Versions $ ...

Did you find this page helpful?