This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // The optimal equilibrium between real-time responsiveness and server load | |
| private static PERIOD_MS = 500; | |
| setInterval(() => { | |
| for (const [userId, connection] of this.activeConnections) { | |
| this.sendPendingEvents(userId, connection); | |
| } | |
| }, BroadcastService.PERIOD_MS); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Core versioning logic (simplified) | |
| for (const connection of activeConnections) { | |
| const missed = eventQueue.filter( | |
| e => e.userId !== connection.userId && connection.version < e.event.version | |
| ); | |
| if (missed.length > 0) { | |
| connection.respond(missed.map(e => e.event)); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void validateArchive(...) { | |
| // Because the engine is dynamic, we must manually verify data integrity. | |
| // Example: Check if the provided ChoiceId actually belongs to the QuestionId. | |
| boolean isValid = questionDetailsList.stream() | |
| .anyMatch(q -> q.getChoices().stream() | |
| .anyMatch(c -> c.getId().equals(targetChoiceId))); | |
| if (!isValid) { | |
| throw new InvalidRequestArgumentException("Inconsistent answer data detected."); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private List<SurveyorActivity> createPhotoActivities(...) { | |
| // Using RxJava's zip operator to synchronize S3 uploads with database persistence. | |
| // The activity record is only created if both the upload and data mapping succeed. | |
| return Observable.zip( | |
| Observable.fromIterable(photos), // Binary files | |
| Observable.fromIterable(photoAnswers), // Answer metadata | |
| (file, answer) -> { | |
| AmazonS3Carrier.BucketObjectDetails s3Details = | |
| amazonS3Service.putImageToBucket(answer.getQuestionId(), file); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // We fetch questions, choices, and previous answers in one optimized query. | |
| public List<QuestionDetails> fetchSurveySchema(Long gameId) { | |
| List<QuestionData> records = queryFactory | |
| .select(Projections.constructor(QuestionData.class, | |
| QQuestion.question.id, | |
| QQuestion.question.content, | |
| QChoice.choice.id, | |
| QChoice.choice.content)) | |
| .from(QQuestionMapping.questionMapping) | |
| .join(QQuestion.question).on(QQuestionMapping.questionId.eq(QQuestion.question.id)) |