PhoenixKit.Modules.Storage.Profiles (phoenix_kit v2.41.0)

Copy Markdown View Source

Storage profiles: where a library's bytes live (V205).

A library points at a profile (PhoenixKit.Modules.Storage.StorageProfile), and the profile lists its buckets with how it uses each (PhoenixKit.Modules.Storage.ProfileBucket: role, what it stores, write priority, serve order, status) and how many copies an object gets. A library with no profile uses the Default, seeded by V205 from the install's buckets and storage_redundancy_copies under a fixed uuid (default_uuid/0), so an install that never touches profiles behaves as it did before.

Every change to a profile or its buckets bumps its revision (bump_revision/1). A file records the profile and revision it was placed by (placed_profile_uuid / placed_revision, NULL meaning the Default at revision 1), which is how the reconciler finds the files that are not where their library's profile wants them.

Summary

Functions

Puts a newly created bucket into the Default profile, the way every new bucket joined the pool before profiles: primary, stores everything, active, its priority as the write priority (0 is the shuffled pool), served after the Default's other buckets (a local one before the remote ones).

Bumps a profile's revision: every file it placed is stale, and the reconciler is queued to bring them up to date.

The number of copies profile wants of an object: :original for an original upload, :derived for anything made from one.

Creates a profile with no buckets.

Whether uuid is the Default profile's.

How many copies of an original the Default keeps (1 when there is no Default yet, as storage_redundancy_copies defaulted to).

The Default profile, with its buckets.

The uuid of the Default profile, fixed on every install.

Deletes a profile. The Default cannot be deleted ({:error, :default}), nor a profile a library uses ({:error, :in_use}).

The profile a file's library uses.

The profile library uses, with its buckets (see profile_uuid_for/1). Falls back to the Default when the library's own is gone.

A profile with its buckets, or nil (also for anything not a uuid).

How many libraries (trashed ones included) use profile_uuid explicitly.

Every profile, the Default first, each with its buckets.

The uuid of the profile library uses: its own, or the Default. Takes a library, a library uuid, or nil (a file with no library is in Media).

Adds bucket_uuid to profile, or changes how the profile uses it, and bumps the profile's revision.

Takes bucket_uuid out of profile and bumps the profile's revision.

Takes bucket_uuid out of every profile, bumping each one's revision. Called when an empty bucket is deleted.

Points library at profile_uuid (nil for the Default). Its files become stale unless the new profile is the one they were placed by.

Updates a profile's name or copy counts; a real change bumps its revision.

Functions

add_to_default(bucket)

@spec add_to_default(PhoenixKit.Modules.Storage.Bucket.t()) :: :ok

Puts a newly created bucket into the Default profile, the way every new bucket joined the pool before profiles: primary, stores everything, active, its priority as the write priority (0 is the shuffled pool), served after the Default's other buckets (a local one before the remote ones).

bump_revision(profile_uuid)

@spec bump_revision(term()) :: :ok

Bumps a profile's revision: every file it placed is stale, and the reconciler is queued to bring them up to date.

copies(storage_profile, atom)

@spec copies(PhoenixKit.Modules.Storage.StorageProfile.t(), :original | :derived) ::
  pos_integer()

The number of copies profile wants of an object: :original for an original upload, :derived for anything made from one.

create_profile(attrs)

@spec create_profile(map()) ::
  {:ok, PhoenixKit.Modules.Storage.StorageProfile.t()}
  | {:error, Ecto.Changeset.t()}

Creates a profile with no buckets.

default?(uuid)

@spec default?(term()) :: boolean()

Whether uuid is the Default profile's.

default_copies()

@spec default_copies() :: pos_integer()

How many copies of an original the Default keeps (1 when there is no Default yet, as storage_redundancy_copies defaulted to).

default_profile()

@spec default_profile() :: PhoenixKit.Modules.Storage.StorageProfile.t() | nil

The Default profile, with its buckets.

default_uuid()

@spec default_uuid() :: String.t()

The uuid of the Default profile, fixed on every install.

delete_profile(profile)

@spec delete_profile(PhoenixKit.Modules.Storage.StorageProfile.t()) ::
  {:ok, PhoenixKit.Modules.Storage.StorageProfile.t()}
  | {:error, :default | :in_use | Ecto.Changeset.t()}

Deletes a profile. The Default cannot be deleted ({:error, :default}), nor a profile a library uses ({:error, :in_use}).

for_file(file)

The profile a file's library uses.

for_library(library)

The profile library uses, with its buckets (see profile_uuid_for/1). Falls back to the Default when the library's own is gone.

get_profile(uuid)

@spec get_profile(term()) :: PhoenixKit.Modules.Storage.StorageProfile.t() | nil

A profile with its buckets, or nil (also for anything not a uuid).

libraries_using(profile_uuid)

@spec libraries_using(term()) :: non_neg_integer()

How many libraries (trashed ones included) use profile_uuid explicitly.

list_profiles()

@spec list_profiles() :: [PhoenixKit.Modules.Storage.StorageProfile.t()]

Every profile, the Default first, each with its buckets.

profile_uuid_for(library_uuid)

@spec profile_uuid_for(PhoenixKit.Modules.Storage.Library.t() | term()) :: String.t()

The uuid of the profile library uses: its own, or the Default. Takes a library, a library uuid, or nil (a file with no library is in Media).

put_bucket(storage_profile, bucket_uuid, attrs)

Adds bucket_uuid to profile, or changes how the profile uses it, and bumps the profile's revision.

remove_bucket(storage_profile, bucket_uuid)

@spec remove_bucket(PhoenixKit.Modules.Storage.StorageProfile.t(), term()) :: :ok

Takes bucket_uuid out of profile and bumps the profile's revision.

remove_bucket_everywhere(bucket_uuid)

@spec remove_bucket_everywhere(term()) :: :ok

Takes bucket_uuid out of every profile, bumping each one's revision. Called when an empty bucket is deleted.

set_library_profile(library, profile_uuid)

@spec set_library_profile(PhoenixKit.Modules.Storage.Library.t(), term()) ::
  {:ok, PhoenixKit.Modules.Storage.Library.t()}
  | {:error, Ecto.Changeset.t() | :not_found}

Points library at profile_uuid (nil for the Default). Its files become stale unless the new profile is the one they were placed by.

update_profile(profile, attrs)

Updates a profile's name or copy counts; a real change bumps its revision.