Skip to content

Commit

Permalink
perf($Exercise): add constraint for concurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnymillergh committed Feb 7, 2020
1 parent d9cae3e commit 5a38ab2
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
42 changes: 40 additions & 2 deletions src/views/exrx-net/components/exercise.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
<span>{{ saveSpecificExerciseProgress }}</span>
<span>{{ saveExerciseProgress }}</span>
</v-card-subtitle>
<v-form v-model="formValidation">
<v-text-field class="concurrency" v-model="concurrency" :rules="rules" type="number" label="Concurrency"
required/>
</v-form>
<v-card-actions>
<v-btn v-debounced-click="handleClickSaveExercise" :loading="loadingSaveExercise" :disabled="loadingSaveExercise"
color="primary" text>
Expand Down Expand Up @@ -51,6 +55,18 @@ export default class Exercise extends Vue {
@Prop() private exerciseLinkSortedByBodyPartList!: ExerciseLinkSortedByBodyPart[]
private loadingContent = false
private formValidation = false
private concurrency = 10
private rules = [
(value: number) => !!value || 'Concurrency is required.',
(value: number) => {
if (value <= 0) {
return 'Concurrency must be larger than 0.'
}
return true
}
]
private loadingSaveExercise = false
// noinspection JSUnusedLocalSymbols
private showExercise = false
Expand All @@ -69,6 +85,10 @@ export default class Exercise extends Vue {
}
async handleClickSaveExercise (): Promise<void> {
if (!this.formValidation) {
this.$toast.warning('Invalid concurrency!')
return
}
if (!this.exerciseLinkSortedByBodyPartList || this.exerciseLinkSortedByBodyPartList.length === 0) {
this.$toast.warning('Invalid data!')
return
Expand All @@ -95,11 +115,22 @@ export default class Exercise extends Vue {
})
this.saveSpecificExerciseProgress = `, exercise amount: ${exerciseAmount}`
for (const item of exercise) {
let concurrentExerciseLinkList = []
// parse and save every specific exercise by exercise link
for (const link of item.exerciseLinkList) {
const index = item.exerciseLinkList.indexOf(link)
this.saveExerciseProgress = `; ${index + 1}. ${link.exerciseName}`
await this.parseSpecificExercise(link)
if (index === 0 || index % this.concurrency !== 0) {
concurrentExerciseLinkList.push(link)
} else {
concurrentExerciseLinkList.push(link)
console.info(`concurrentExerciseLinkList ${index}`, concurrentExerciseLinkList)
const tasks = [] as Promise<unknown>[]
concurrentExerciseLinkList.forEach(value => {
tasks.push(this.parseSpecificExercise(value))
})
await Promise.all(tasks)
concurrentExerciseLinkList = []
}
}
}
}
Expand Down Expand Up @@ -245,3 +276,10 @@ export default class Exercise extends Vue {
}
}
</script>

<style scoped>
.concurrency {
margin-left: 16px;
margin-right: 16px;
}
</style>
20 changes: 19 additions & 1 deletion src/views/exrx-net/components/muscle-link.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
<v-card-subtitle>
<span>Length: {{ muscleLinkList.length }} {{ updateMuscleDetailsProgress }}</span>
</v-card-subtitle>
<v-text-field class="concurrency" v-model="concurrency" type="number" label="Concurrency" required/>
<v-form v-model="formValidation">
<v-text-field class="concurrency" v-model="concurrency" :rules="rules" type="number" label="Concurrency"
required/>
</v-form>
<v-card-actions>
<v-btn v-debounced-click="handleClickUpdateMuscleDetails" :loading="loadingUpdateMuscleDetails"
:disabled="loadingUpdateMuscleDetails" color="primary" text>
Expand Down Expand Up @@ -41,7 +44,18 @@ import { muscleApi } from '@/requests/muscle-api'
export default class MuscleLinkView extends Vue {
@Prop() private muscleLinkList!: Array<MuscleLink>
private formValidation = false
private concurrency = 5
private rules = [
(value: number) => !!value || 'Concurrency is required.',
(value: number) => {
if (value <= 0) {
return 'Concurrency must be larger than 0.'
}
return true
}
]
private loadingContent = false
// muscleLinkList: [] as Array<MuscleLink>,
private loadingUpdateMuscleDetails = false
Expand Down Expand Up @@ -118,6 +132,10 @@ export default class MuscleLinkView extends Vue {
}
async handleClickUpdateMuscleDetails (): Promise<void> {
if (!this.formValidation) {
this.$toast.warning('Invalid concurrency!')
return
}
if (!this?.muscleLinkList.length) {
this.$toast.warning('Invalid data!')
return
Expand Down

0 comments on commit 5a38ab2

Please sign in to comment.