improvement: use cached to_tenant when setting tenant attribute (#1021)

This commit is contained in:
Riccardo Binetti 2024-04-14 17:53:09 +02:00 committed by GitHub
parent 7e277673fd
commit 3338b343ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 4 additions and 8 deletions

View file

@ -513,8 +513,7 @@ defmodule Ash.Actions.Create.Bulk do
Ash.Resource.Info.multitenancy_strategy(changeset.resource) == :attribute do
attribute = Ash.Resource.Info.multitenancy_attribute(changeset.resource)
{m, f, a} = Ash.Resource.Info.multitenancy_parse_attribute(changeset.resource)
tenant = Ash.ToTenant.to_tenant(changeset.tenant, changeset.resource)
attribute_value = apply(m, f, [tenant | a])
attribute_value = apply(m, f, [changeset.to_tenant | a])
Ash.Changeset.force_change_attribute(changeset, attribute, attribute_value)
else

View file

@ -497,8 +497,7 @@ defmodule Ash.Actions.Create do
Ash.Resource.Info.multitenancy_strategy(changeset.resource) == :attribute do
attribute = Ash.Resource.Info.multitenancy_attribute(changeset.resource)
{m, f, a} = Ash.Resource.Info.multitenancy_parse_attribute(changeset.resource)
tenant = Ash.ToTenant.to_tenant(changeset.tenant, changeset.resource)
attribute_value = apply(m, f, [tenant | a])
attribute_value = apply(m, f, [changeset.to_tenant | a])
Ash.Changeset.force_change_attribute(changeset, attribute, attribute_value)
else

View file

@ -1148,8 +1148,7 @@ defmodule Ash.Actions.Read do
if multitenancy_attribute && query.tenant do
{m, f, a} = Ash.Resource.Info.multitenancy_parse_attribute(query.resource)
tenant = Ash.ToTenant.to_tenant(query.tenant, query.resource)
attribute_value = apply(m, f, [tenant | a])
attribute_value = apply(m, f, [query.to_tenant | a])
Ash.Query.filter(query, ^ref(multitenancy_attribute) == ^attribute_value)
else
query

View file

@ -581,8 +581,7 @@ defmodule Ash.Actions.Update do
attribute = Ash.Resource.Info.multitenancy_attribute(changeset.resource)
{m, f, a} = Ash.Resource.Info.multitenancy_parse_attribute(changeset.resource)
tenant = Ash.ToTenant.to_tenant(changeset.tenant, changeset.resource)
attribute_value = apply(m, f, [tenant | a])
attribute_value = apply(m, f, [changeset.to_tenant | a])
Ash.Changeset.force_change_attribute(changeset, attribute, attribute_value)
else