Skip to content

Commit

Permalink
Optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
kozmi55 committed Jul 28, 2017
1 parent 1f5c587 commit 1a6f0ef
Showing 1 changed file with 7 additions and 7 deletions.
Expand Up @@ -32,15 +32,19 @@ class UserRepository(
}

private fun mapAnswersToAnswerViewModels(answers: List<Answer>): Single<List<AnswerViewModel>> {
val ids = answers
val processedAnswers = answers
.filter { it.accepted }
.take(3)

val ids = processedAnswers
.map { it.questionId.toString() }
.joinToString(separator = ";")

val questionsListModel = questionService.getQuestionById(ids)

return questionsListModel
.map { questionListModel: QuestionListModel? ->
addTitlesToAnswers(answers, questionListModel?.items ?: emptyList()) }
addTitlesToAnswers(processedAnswers, questionListModel?.items ?: emptyList()) }
}

private fun addTitlesToAnswers(answers: List<Answer>, questions: List<Question>) : List<AnswerViewModel> {
Expand All @@ -58,10 +62,6 @@ class UserRepository(
val favorites = favoritesModel.items
.take(3)

val answers = answersModel
.filter { it.accepted }
.take(3)

return DetailsModel(questions, answers, favorites)
return DetailsModel(questions, answersModel, favorites)
}
}

0 comments on commit 1a6f0ef

Please sign in to comment.