keygen-sh / keygen-api

Keygen is a fair source software licensing and distribution API built with Ruby on Rails. For developers, by developers.
https://keygen.sh
Other
846 stars 58 forks source link

Create a materialized view for request logs #566

Open ezekg opened 2 years ago

ezekg commented 2 years ago

We use an ILIKE on e.g. url so we need a gin_trgm_ops index. But we need to keep in mind https://iamsafts.com/posts/postgres-gin-performance/.

ezekg commented 2 years ago

We also need to swap out url to status here: https://github.com/ezekg/keygen-api/blob/master/db/schema.rb#L441 Wait, these are used for the top URLs endpoint.

ezekg commented 2 years ago

Should we also add indexes to status, ip and method? Maybe we should create a view for the current week? Each index slows down writes.

ezekg commented 2 years ago

Ref: https://www.norydev.com/writing/pg-mat-views-for-better-performance-in-rails

ezekg commented 2 years ago

Ref: https://github.com/scenic-views/scenic