Skip to content

Commit

Permalink
Merge 674672f into 2ac74d0
Browse files Browse the repository at this point in the history
  • Loading branch information
hauleth committed Apr 26, 2018
2 parents 2ac74d0 + 674672f commit a33275a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/accent/auth/user_auth_fetcher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule Accent.UserAuthFetcher do
defp fetch_user("Bearer " <> token) when is_binary(token) do
from(
user in User,
left_join: access_token in assoc(user, :access_tokens),
inner_join: access_token in assoc(user, :access_tokens),
where: access_token.token == ^token,
where: is_nil(access_token.revoked_at)
)
Expand Down
4 changes: 2 additions & 2 deletions lib/accent/scopes/translation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ defmodule Accent.Scopes.Translation do
## Examples
iex> Accent.Scopes.Translation.from_project(Accent.Translation, "test")
#Ecto.Query<from t in Accent.Translation, left_join: p in assoc(t, :project), where: p.id == ^"test">
#Ecto.Query<from t in Accent.Translation, join: p in assoc(t, :project), where: p.id == ^"test">
"""
@spec from_project(Ecto.Queryable.t(), String.t()) :: Ecto.Queryable.t()
def from_project(query, project_id) do
from(
translation in query,
left_join: project in assoc(translation, :project),
inner_join: project in assoc(translation, :project),
where: project.id == ^project_id
)
end
Expand Down
40 changes: 40 additions & 0 deletions priv/repo/migrations/20180426084509_add_missing_indices.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
defmodule Accent.Repo.Migrations.AddMissingIndices do
use Ecto.Migration

def change do
create index(:auth_access_tokens, [:user_id], where: "revoked_at IS NULL")

create index(:auth_providers, [:user_id])

create index(:comments, [:user_id])
create index(:comments, [:translation_id])

create index(:documents, [:project_id])

create index(:integrations, [:project_id])
create index(:integrations, [:user_id])

create index(:operations, [:translation_id])
create index(:operations, [:revision_id])
create index(:operations, [:project_id])
create index(:operations, [:comment_id])
create index(:operations, [:batch_operation_id])
create index(:operations, [:rollbacked_operation_id])
create index(:operations, [:user_id])
create index(:operations, [:document_id])
create index(:operations, [:version_id])

create index(:projects, [:language_id])

create index(:revisions, [:project_id])
create index(:revisions, [:language_id])
create index(:revisions, [:master_revision_id])

create index(:translations, [:document_id])
create index(:translations, [:version_id])
create index(:translations, [:source_translation_id])

create index(:versions, [:project_id])
create index(:versions, [:user_id])
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
defmodule Accent.Repo.Migrations.AddTrigramIndicesOnSearchableFields do
use Ecto.Migration

def change do
execute("CREATE EXTENSION pg_trgm", "DROP EXTENSION pg_trgm")

create index(:languages, ["name gin_trgm_ops"], using: :gin)
create index(:projects, ["name gin_trgm_ops"], using: :gin)
create index(:translations, ["key gin_trgm_ops", "corrected_text gin_trgm_ops"], using: :gin)
end
end

0 comments on commit a33275a

Please sign in to comment.