Skip to content

Commit

Permalink
Fix expensive project dashboard query
Browse files Browse the repository at this point in the history
  • Loading branch information
simonprev committed Mar 3, 2024
1 parent adc0c1a commit 41516d8
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 62 deletions.
14 changes: 11 additions & 3 deletions lib/accent/scopes/operation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,19 @@ defmodule Accent.Scopes.Operation do
Accent.Operation
iex> Accent.Scopes.Operation.filter_from_project(Accent.Operation, "test")
#Ecto.Query<from o0 in Accent.Operation, left_join: r1 in assoc(o0, :revision), where: r1.project_id == ^"test" or o0.project_id == ^"test">
iex> Accent.Scopes.Operation.filter_from_project(Accent.Operation, "test", "sync")
#Ecto.Query<from o0 in Accent.Operation, where: o0.project_id == ^"test">
"""
@spec filter_from_project(Ecto.Queryable.t(), String.t() | nil) :: Ecto.Queryable.t()
def filter_from_project(query, nil), do: query
@spec filter_from_project(Ecto.Queryable.t(), String.t() | nil, String.t() | nil) :: Ecto.Queryable.t()
def filter_from_project(query, project_id, action \\ nil)
def filter_from_project(query, nil, _), do: query

def filter_from_project(query, project_id) do
def filter_from_project(query, project_id, action)
when action in ~w(sync batch_sync batch_merge create_version document_delete merge new_slave version_new) do
from(query, where: [project_id: ^project_id])
end

def filter_from_project(query, project_id, _) do
from(o in query,
left_join: r in assoc(o, :revision),
where: r.project_id == ^project_id or o.project_id == ^project_id
Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/resolvers/project.ex
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ defmodule Accent.GraphQL.Resolvers.Project do
@spec last_activity(Project.t(), any(), GraphQLContext.t()) :: {:ok, Operation.t() | nil}
def last_activity(project, args, _) do
Operation
|> OperationScope.filter_from_project(project.id)
|> OperationScope.filter_from_action(args[:action])
|> OperationScope.filter_from_project(project.id, args[:action])
|> OperationScope.order_last_to_first()
|> Query.limit(1)
|> Repo.one()
Expand Down
1 change: 1 addition & 0 deletions vendor/language_tool/lib/language_tool/backend.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ defmodule LanguageTool.Backend do
backend
else
Logger.warning("LanguageTool could not be started. Install JRE and build the jar in #{jar_file()} to enable it")
nil
end
end

Expand Down
6 changes: 3 additions & 3 deletions webapp/app/components/dashboard-revisions/item/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ export default class DashboardRevisionsItem extends Component<Args> {
);
}

get reviewsCount() {
const {conflictsCount, translationsCount} = this.args.revision;
get toReviewCount() {
const {reviewedCount, translationsCount} = this.args.revision;

return translationsCount - conflictsCount;
return translationsCount - reviewedCount;
}

get languageName() {
Expand Down
4 changes: 3 additions & 1 deletion webapp/app/locales/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@
"rtl_badge": "RTL",
"rtl": "Right to left text",
"correct_all_button": "Mark all strings as reviewed",
"uncorrect_all_button": "Put all strings back in review"
"uncorrect_all_button": "Put all strings back in review",
"stats_translated": "translated",
"stats_to_review": "to review"
}
},
"date_tag": {
Expand Down
4 changes: 3 additions & 1 deletion webapp/app/locales/fr-ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@
"rtl_badge": "RTL",
"rtl": "Texte de droite à gauche",
"correct_all_button": "Marquer toutes les chaînes comme vérifiées",
"uncorrect_all_button": "Remettre toutes les chaînes à réviser"
"uncorrect_all_button": "Remettre toutes les chaînes à réviser",
"stats_translated": "traduits",
"stats_to_review": "à réviser"
}
},
"date_tag": {
Expand Down
2 changes: 2 additions & 0 deletions webapp/app/queries/project-dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface ProjectDashboardQueryResponse {
id: string;
conflictsCount: number;
reviewedCount: number;
translatedCount: number;
translationsCount: number;
isMaster: boolean;
name: string;
Expand Down Expand Up @@ -131,6 +132,7 @@ export default gql`
id
conflictsCount
reviewedCount
translatedCount
translationsCount
isMaster
name
Expand Down
3 changes: 2 additions & 1 deletion webapp/app/styles/components/conflicts-list/group.scss
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
color: #959595;
gap: 6px;
font-weight: 300;
flex-shrink: 0;

&::before {
content: '/';
Expand All @@ -84,7 +85,7 @@
position: sticky;
top: 46px;
display: inline-flex;
align-items: center;
align-items: flex-start;
gap: 5px;
background: var(--content-background);
padding: 2px 6px;
Expand Down
7 changes: 3 additions & 4 deletions webapp/app/styles/components/dashboard-revisions.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
align-items: center;
justify-content: center;
width: 100%;
margin: 20px auto 10px;
margin: 0 auto 10px;
}

.numberStat-reviewPercentage {
Expand Down Expand Up @@ -100,8 +100,7 @@

.slaves {
display: flex;
flex-wrap: wrap;
align-items: flex-start;
flex-direction: column;
}

.empty-slaves-button {
Expand Down Expand Up @@ -147,7 +146,7 @@
}

.master {
margin: 25px 0 5px;
margin: 25px 0 0;
}

.stats-title-links {
Expand Down
59 changes: 39 additions & 20 deletions webapp/app/styles/components/dashboard-revisions/item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,13 @@
transition: 0.2s ease-in-out;
transition-property: box-shadow;
position: relative;
flex: 1 1 calc(50% - 20px);
justify-content: space-between;
max-width: 50%;
margin-bottom: 20px;
margin-right: 20px;
width: 100%;
margin-bottom: 10px;
border-radius: var(--border-radius);
box-shadow:
0 6px 25px var(--shadow-color),
0 2px 7px var(--shadow-color);

&:nth-child(even) {
flex: 1 1 50%;
margin-right: 0;
}
}

.dashboard-revisions-item.low-percentage {
Expand Down Expand Up @@ -64,8 +57,7 @@

.language {
display: flex;
align-items: flex-end;
justify-content: space-between;
flex-direction: column;
color: var(--color-grey);
}

Expand All @@ -84,21 +76,43 @@
}

.language-reviewedPercentage {
display: block;
margin-top: 5px;
display: flex;
align-items: baseline;
gap: 4px;
font-weight: normal;
font-size: 25px;
font-size: 22px;
color: var(--color-grey);
letter-spacing: -2px;
}

.language-reviewedPercentage-symbol {
font-size: 13px;
}

.reviewedStats {
padding: 2px 0 1px 7px;
border-radius: var(--border-radius);
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
color: var(--color-grey);
font-size: 12px;
font-family: var(--font-monospace);
}

.reviewedStats-translatedCount,
.reviewedStats-translationsCount,
.reviewedStats-reviewedCount {
font-family: var(--font-primary);
color: var(--color-grey);
margin: 0 3px;
font-size: 11px;
text-decoration: none;
}

.reviewedStats-reviewedCount {
font-weight: bold;
}

.actionsButton {
transition: 0.2s ease-in-out;
transition-property: opacity;
Expand All @@ -116,24 +130,29 @@
&:focus,
&:hover {
.actionsButton-icon {
stroke: var(--color-primary);
opacity: 1;
}
}
}

.actionsButton-icon {
stroke: var(--color-grey);
opacity: 0.4;
transition: 0.2s ease-in-out;
transition-property: stroke;
width: 15px;
height: 15px;
transition-property: stroke, opacity;
width: 13px;
height: 13px;
}

.actions {
margin: 10px 0 0;
display: flex;
flex-direction: column;
gap: 4px;

:global(.button) {
justify-content: center;
}
}

.actionItem-text {
Expand Down
52 changes: 24 additions & 28 deletions webapp/app/templates/components/dashboard-revisions/item.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,33 @@
{{inline-svg 'assets/gear.svg' local-class='actionsButton-icon'}}
</span>
<span local-class='language'>
{{#if (get @permissions 'index_translations')}}
<LinkTo @route='logged-in.project.revision.translations' @models={{array @project.id @revision.id}} local-class='language-name'>
{{this.languageName}}
{{#if this.rtl}}
<AccBadge class='tooltip tooltip--top' title={{t 'components.dashboard_revisions.item.rtl'}}>
{{t 'components.dashboard_revisions.item.rtl_badge'}}
</AccBadge>
{{/if}}
<span local-class='language-reviewedPercentage'>
{{this.correctedKeysPercentage}}
%
</span>
</LinkTo>
{{else}}
<span local-class='language-name'>
{{this.languageName}}
<span local-class='language-reviewedPercentage'>
{{this.correctedKeysPercentage}}
%
</span>
</span>
{{/if}}
<LinkTo @route='logged-in.project.revision.translations' @models={{array @project.id @revision.id}} local-class='language-name'>
{{this.languageName}}
{{#if this.rtl}}
<AccBadge class='tooltip tooltip--top' title={{t 'components.dashboard_revisions.item.rtl'}}>
{{t 'components.dashboard_revisions.item.rtl_badge'}}
</AccBadge>
{{/if}}
</LinkTo>

<span local-class='reviewedStats'>
<span local-class='reviewedStats-reviewedCount'>
{{this.reviewsCount}}
</span>
/
<span local-class='reviewedStats-translationsCount'>
{{@revision.translationsCount}}
<span local-class='language-reviewedPercentage'>
{{this.correctedKeysPercentage}}<span local-class='language-reviewedPercentage-symbol'>%</span>
</span>

<div>
<LinkTo @route='logged-in.project.conflicts' @model={{@project.id}} local-class='reviewedStats-reviewedCount'>
{{this.toReviewCount}}
{{t 'components.dashboard_revisions.item.stats_to_review'}}
</LinkTo>

{{#unless @revision.isMaster}}
<span local-class='reviewedStats-translatedCount'>
{{@revision.translatedCount}}
{{t 'components.dashboard_revisions.item.stats_translated'}}
</span>
{{/unless}}
</div>
</span>
</span>

Expand Down

0 comments on commit 41516d8

Please sign in to comment.