storj/satellite/satellitedb/dbx/project.dbx
Michal Niewrzal ee720040c9 satellite/metainfo: use project limit cache with limiter
Metainfo needs to know rate and burst limit to be able to limit users
requests. We made cache for per project limiter but to make single
instance we need to know about limits. So far we were doing direct DB
call to get rate/burst limit for project but it's generating lots of
DB requests and can be easily cached as we even have project limit cache.

This change extends project limit cache with rate/burst limit and starts
using this change while creating project limiter instance for metainfo.

Because data size kept in project limit cache is quite small this change
also bumps a bit default capacity of the cache.

Fixes https://github.com/storj/storj/issues/5663

Change-Id: Icb42ec1632bfa0c9f74857b559083dcbd054d071
2023-03-14 08:11:11 +00:00

192 lines
6.0 KiB
Plaintext

// project contains information about a user project.
model project (
key id
index (
name projects_public_id_index
fields public_id
)
// id is a UUID used for identifying the project.
field id blob
// public_id is a UUID that's used in web requests.
field public_id blob ( nullable )
// name is a identifier that's shown to the user.
field name text ( updatable )
// description helps users to clarify what the project is for.
field description text ( updatable )
// usage_limit defines maximum allowed bytes that can be stored.
field usage_limit int64 ( nullable, updatable )
// bandwidth_limit defines maximum allowed bandwidth per month in bytes.
field bandwidth_limit int64 ( nullable, updatable )
// user_specified_usage_limit is set by the user to limit their bytes that can be stored.
field user_specified_usage_limit int64 ( nullable, updatable )
// user_specified_bandwidth_limit is set by the user to limit their bytes that downloaded.
field user_specified_bandwidth_limit int64 ( nullable, updatable )
// segment_limit specifies how many segments can be stored in the project.
field segment_limit int64 ( nullable, updatable, default 1000000)
// rate_limit defines maximum requests per second the project can use.
// See golang.org/x/time/rate#Limiter for details.
field rate_limit int ( nullable, updatable )
// burst_limit defines number of requests that are not throttled by rate_limit.
// See golang.org/x/time/rate#Limiter for details.
field burst_limit int ( nullable, updatable )
// max_buckets is the maximum number of buckets that can be created for the project.
field max_buckets int ( nullable, updatable )
// partner_id is an UUID that refers to rewards.PartnersStaticDB.
// deprecated: use user_agent instead.
field partner_id blob ( nullable )
// user_agent is the referred partner who created the project.
field user_agent blob ( nullable )
// owner_id refers to the user UUID in user.id.
field owner_id blob
// salt is used for salting the user passphrase for the content.
field salt blob ( nullable )
// created_at indicates when the project was created.
field created_at timestamp ( autoinsert )
)
create project ( )
update project ( where project.id = ? )
delete project ( where project.id = ? )
read one (
select project.salt
where project.id = ?
)
read one (
select project
where project.public_id = ?
)
read one (
select project
where project.id = ?
)
read one (
select project.usage_limit
where project.id = ?
)
read one (
select project.bandwidth_limit
where project.id = ?
)
read one (
select project.user_specified_usage_limit
where project.id = ?
)
read one (
select project.user_specified_bandwidth_limit
where project.id = ?
)
read one (
select project.segment_limit
where project.id = ?
)
read one (
select project.max_buckets
where project.id = ?
)
read one (
select project.bandwidth_limit project.usage_limit project.segment_limit project.rate_limit project.burst_limit
where project.id = ?
)
read all (
select project
)
read all (
select project
where project.created_at < ?
orderby asc project.created_at
)
read all (
select project
where project.owner_id = ?
orderby asc project.created_at
)
read all (
select project
join project.id = project_member.project_id
where project_member.member_id = ?
orderby asc project.name
)
read limitoffset (
select project
where project.created_at < ?
orderby asc project.created_at
)
// project_member is an association table between projects and users.
// It indicates which users have access to the specific project.
model project_member (
key member_id project_id
// member_id is the user that can access the project.
field member_id user.id cascade
// project_id is the project that can be accessed.
field project_id project.id cascade
// created_at indicates when the user was added as a member.
field created_at timestamp ( autoinsert )
)
create project_member ( )
delete project_member (
where project_member.member_id = ?
where project_member.project_id = ?
)
read all (
select project_member
where project_member.member_id = ?
)
// api_key is used to authenticate in requests.
model api_key (
key id
unique head
unique name project_id
// id is a UUID for the api key.
field id blob
// project_id is a UUID that refers to project.id.
field project_id project.id cascade
// head is restrictions for the api key.
field head blob
// name helps users to identify the purpose of the api key.
field name text (updatable)
// secret is the macaroon secret.
field secret blob
// partner_id is an UUID that refers to rewards.PartnersStaticDB.
// deprecated: use user_agent instead.
field partner_id blob (nullable)
// user_agent is the referred partner who created the project.
field user_agent blob (nullable)
// created_at indicates when the api key was added.
field created_at timestamp (autoinsert)
)
create api_key ( )
update api_key (
where api_key.id = ?
noreturn
)
delete api_key ( where api_key.id = ? )
read one (
select api_key
where api_key.id = ?
)
read one (
select api_key
where api_key.head = ?
)
read one (
select api_key
where api_key.name = ?
where api_key.project_id = ?
)