Files
ubicloud/clover_api.rb
Jeremy Evans f4f33c119c Add CloverBase#current_user
Instead of setting @current_user twice in the main CloverWeb
route block and once in the CloverApi route block, add a method
that accesses it lazily, and sets it if it has not already been set.

This broke one spec that expected create_account when Account.[]
raised an error.  Remove the mocking and define a route only in
the test environment that can be used when you want to simulate
an exception.

Changes to the routes and views made with:

```
sed -i -e 's/@current_user/current_user/' `git grep -l '@current_user' routes views`
```

This is potentially slower, as method calls are slower than
instance variable accesses.  However, this avoids multiple
queries for users logged in via the remember token, and queries
are way more expensive than either method calls or instance
variable accesses.

For CloverApi, since the user was only set once, there is
no performance benefit from doing this.  However, since the
long term plan is to merge CloverWeb and CloverApi, and this
change would be necessary in that case, I took care of CloverApi
in this commit.
2024-10-28 14:40:13 -07:00

2.2 KiB