Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T#2457/bulk achievement load #2476

Merged
merged 3 commits into from
Dec 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions service/src/main/java/skills/skillLoading/SkillsLoader.groovy
Original file line number Diff line number Diff line change
@@ -1235,7 +1235,6 @@ class SkillsLoader {
})
}

Date achievedOn = achievedLevelRepository.getAchievedDateByUserIdAndProjectIdAndSkillId(userId, skillDef.projectId, skillDef.skillId)
Date expirationDate
Date mostRecentlyPerformedOn
Date lastExpirationDate
@@ -1244,7 +1243,7 @@ class SkillsLoader {
if (skillDefAndUserPoints.attributes && skillDefAndUserPoints.attributes.type == SkillAttributesDef.SkillAttributesType.AchievementExpiration) {
ExpirationAttrs expirationAttrs = skillAttributeService.convertAttrs(skillDefAndUserPoints.attributes, ExpirationAttrs)
expirationDate = expirationAttrs.nextExpirationDate
if(!achievedOn) {
if(!skillDefAndUserPoints.achievedOn) {
lastExpirationDate = skillDefAndUserPoints.expiredOn
}
isMotivationalSkill = expirationAttrs?.expirationType == ExpirationAttrs.DAILY
@@ -1273,7 +1272,7 @@ class SkillsLoader {
pointIncrementInterval: skillDef.pointIncrementInterval,
maxOccurrencesWithinIncrementInterval: skillDef.numMaxOccurrencesIncrementInterval,
totalPoints: skillDef.totalPoints,
achievedOn: achievedOn,
achievedOn: skillDefAndUserPoints.achievedOn,
dependencyInfo: skillDefAndUserPoints.dependencyInfo,
badgeDependencyInfo: badgeDependencySummary,
selfReporting: loadSelfReportingFromApproval(skillDefAndUserPoints),
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@ import skills.storage.repos.QuizToSkillDefRepo
import skills.storage.repos.SkillApprovalRepo
import skills.storage.repos.SkillDefRepo
import skills.storage.repos.SkillDefWithExtraRepo
import skills.storage.repos.UserAchievedLevelRepo
import skills.storage.repos.UserPerformedSkillRepo
import skills.storage.repos.UserPointsRepo

@@ -70,6 +71,9 @@ class SubjectDataLoader {
@Autowired
ExpiredUserAchievementRepo expiredUserAchievementRepo

@Autowired
UserAchievedLevelRepo achievedLevelRepository

static class SkillsAndPoints {
SkillDef skillDef
int points
@@ -90,6 +94,7 @@ class SubjectDataLoader {
List<SkillTag> tags = []
SkillAttributesDef attributes
Date expiredOn
Date achievedOn
}

static class SkillsData {
@@ -145,6 +150,7 @@ class SubjectDataLoader {
skillsAndPoints = handleBadges(projectId, skillsAndPoints)
skillsAndPoints = handleSkillTags(projectId, skillsAndPoints)
skillsAndPoints = handleSkillQuizInfo(projectId, skillsAndPoints)
skillsAndPoints = handleAchievements(projectId, userId, skillsAndPoints)
skillsAndPoints = handleSkillExpirations(projectId, userId, skillsAndPoints)

new SkillsData(childrenWithPoints: skillsAndPoints)
@@ -178,9 +184,26 @@ class SubjectDataLoader {
return skillsAndPoints;
}

private List<SkillsAndPoints> handleSkillExpirations(String projectId, String userId, List<SkillsAndPoints> skillsAndPoints) {
private List<SkillsAndPoints> handleAchievements(String projectId, String userId, List<SkillsAndPoints> skillsAndPoints) {
if(projectId) {
List<String> skillIds = collectSkillIds(skillsAndPoints)
List<UserAchievement> achievedSkills = achievedLevelRepository.getAchievedDateByUserIdAndProjectIdAndSkillBatch(userId, projectId, skillIds)
if (achievedSkills) {
skillsAndPoints.each { it ->
List<UserAchievement> achievements = achievedSkills.findAll{skill -> skill.skillId == it.skillDef.skillId}
if(achievements) {
achievements?.sort { skill -> skill.achievedOn }
it.achievedOn = achievements.first()?.achievedOn
}
}
}
}
return skillsAndPoints
}

private List<SkillsAndPoints> handleSkillExpirations(String projectId, String userId, List<SkillsAndPoints> skillsAndPoints) {
if(projectId) {
List<String> skillIds = collectUnachievedSkillIds(skillsAndPoints)
def expiredSkills = expiredUserAchievementRepo.findMostRecentExpirationForAllSkills(projectId, userId, skillIds)
if (expiredSkills) {
skillsAndPoints.each { it ->
@@ -254,6 +277,22 @@ class SubjectDataLoader {
return skillIds
}

private List<String> collectUnachievedSkillIds(List<SkillsAndPoints> skillsAndPoints) {
List<String> skillIds = []
skillsAndPoints.forEach { it ->
if(!it.achievedOn) {
if (it.skillDef.type == SkillDef.ContainerType.SkillsGroup) {
if (it.children) {
skillIds.addAll(it.children.findAll{ child -> !child.achievedOn }.collect { child -> child.skillDef.skillId })
}
} else if (it.skillDef.type == SkillDef.ContainerType.Skill) {
skillIds.add(it.skillDef.skillId)
}
}
}
return skillIds
}

private List<SkillsAndPoints> handleGroupDescriptions(String projectId, List<SkillsAndPoints> skillsAndPoints, List<SkillRelDef.RelationshipType> relationshipTypes) {
if (relationshipTypes.containsAll([SkillRelDef.RelationshipType.SkillsGroupRequirement, SkillRelDef.RelationshipType.GroupSkillToSubject])) {
List<SkillsAndPoints> groups = skillsAndPoints.findAll({ it.skillDef.type == SkillDef.ContainerType.SkillsGroup })
Original file line number Diff line number Diff line change
@@ -48,6 +48,10 @@ interface UserAchievedLevelRepo extends CrudRepository<UserAchievement, Integer>
@Query('''select ua.achievedOn from UserAchievement ua where ua.userId= ?1 and ua.projectId=?2 and ua.skillId=?3''')
Date getAchievedDateByUserIdAndProjectIdAndSkillId(String userId, String projectId, String skillId)

@Nullable
@Query('''select ua from UserAchievement ua where ua.userId = ?1 and ua.projectId = ?2 and ua.skillId in ?3''')
List<UserAchievement> getAchievedDateByUserIdAndProjectIdAndSkillBatch(String userId, String projectId, List<String> skillId)

@Query('''select ua from UserAchievement ua where ua.userId = ?1 and ua.projectId in ?2''')
List<UserAchievement> findAllByUserAndProjectIds(String userId, Collection<String> projectId)