Tyler Hallada 519fcb4c5a Add caching with LRU cache under mutex
Caches responses of each GET handler in a separate capacity-limited cache (as a
custom clone-able `CachedResponse` struct). Subsequent requests will build a
`Response` from the cached bytes instead of re-querying the database and
re-serializing the JSON. This greatly speeds up the list endpoints and
`get_interior_ref_list`.

Also caches the api-key-to-id mapping for `Owner`s in order to speed up frequent
authentications.

Each create handler clears the entire list response cache. Each delete handler
also clears the entire list response cache and deletes the cached response for
that key. Deleting an owner also deletes their entry in the
`owner_ids_by_api_key` cache.
2020-08-01 00:25:04 -04:00
2020-07-23 00:12:56 -04:00
2020-07-23 00:12:56 -04:00

Development Setup

  1. Install and run postgres.
  2. Create postgres user and database (and add uuid extension while you're there ): createuser shopkeeper createdb shopkeeper sudo -u postgres -i psql postgres=# ALTER DATABASE shopkeeper OWNER TO shopkeeper; \password shopkeeper postgres=# CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
  3. Save password somewhere safe and then and add a .env file to the project directory with the contents: DATABASE_URL=postgresql://shopkeeper:@localhost/shopkeeper RUST_LOG="shopkeeper=debug" HOST="http://localhost:3030"
  4. Create a new file at src/db/refinery.toml with the contents: [main] db_type = "Postgres" db_host = "localhost" db_port = "5432" db_user = "shopkeeper" db_pass = "" db_name = "shopkeeper"
  5. Run cargo run -- -m which will compile the app in debug mode and run the database migrations.
  6. Run ./devserver.sh to run the dev server (by default it listens at 127.0.0.1:3030).

Todo

  • Add HTTP header authentication for endpoints that modify an owner's data.
  • Add DELETE endpoints for existing resources.
  • Add endpoints for the other models.
  • Add caching. Not sure how to do this exactly. Could use Redis, Varnish, Nginx, or a lib resident in the rust web server process. I'll probably need to do invalidations as transactions are made, or interiors are updated.
  • Make self-contained docker container that can run the app without any setup.
  • Add rate-limiting per IP address. The tower crate has a service that might be useful for this.
Description
API for the Bazaar Realm Skyrim mod
Readme 226 KiB
Languages
Rust 99.2%
Dockerfile 0.5%
PLpgSQL 0.2%