Skip to content

Commit 36f7073

Browse files
committed
SEBSP-210 screenshot data session cache PoC impl
1 parent 2321322 commit 36f7073

13 files changed

+286
-165
lines changed

src/main/java/ch/ethz/seb/sps/server/datalayer/dao/ScreenshotDataDAO.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828

2929
public interface ScreenshotDataDAO extends EntityDAO<ScreenshotData, ScreenshotData> {
3030

31-
Result<Collection<ScreenshotData>> allOfSession(String sessionUUID);
31+
Result<Collection<ScreenshotDataRecord>> allOfSession(String sessionUUID);
3232

33-
Result<ScreenshotDataRecord> getAt(String sessionUUID, Long at);
33+
//Result<ScreenshotDataRecord> getAt(String sessionUUID, Long at);
3434

35-
Result<Long> getIdAt(String sessionUUID, Long at);
35+
//Result<Long> getIdAt(String sessionUUID, Long at);
3636

3737
//Result<Long> getLatestImageId(String sessionUUID);
3838

src/main/java/ch/ethz/seb/sps/server/datalayer/dao/impl/ClientAccessDAOBatis.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,14 @@ public boolean isActive(final String modelId) {
102102
return false;
103103
}
104104

105+
final Long pk = modelIdToPK(modelId);
106+
if (pk == null) {
107+
return false;
108+
}
109+
105110
return this.clientAccessRecordMapper
106111
.countByExample()
107-
.where(ClientAccessRecordDynamicSqlSupport.id, isEqualTo(Long.valueOf(modelId)))
112+
.where(ClientAccessRecordDynamicSqlSupport.id, isEqualTo(pk))
108113
.and(ClientAccessRecordDynamicSqlSupport.terminationTime, SqlBuilder.isNull())
109114
.build()
110115
.execute() > 0;

src/main/java/ch/ethz/seb/sps/server/datalayer/dao/impl/ExamDAOBatis.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,14 @@ public boolean isActive(final String modelId) {
328328
return false;
329329
}
330330

331+
final Long pk = modelIdToPK(modelId);
332+
if (pk == null) {
333+
return false;
334+
}
335+
331336
return this.examRecordMapper
332337
.countByExample()
333-
.where(ExamRecordDynamicSqlSupport.id, isEqualTo(Long.valueOf(modelId)))
338+
.where(ExamRecordDynamicSqlSupport.id, isEqualTo(pk))
334339
.and(ExamRecordDynamicSqlSupport.terminationTime, SqlBuilder.isNull())
335340
.build()
336341
.execute() > 0;

src/main/java/ch/ethz/seb/sps/server/datalayer/dao/impl/GroupDAOBatis.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,14 @@ public boolean isActive(final String modelId) {
382382
return false;
383383
}
384384

385+
final Long pk = modelIdToPK(modelId);
386+
if (pk == null) {
387+
return false;
388+
}
389+
385390
return this.groupRecordMapper
386391
.countByExample()
387-
.where(GroupRecordDynamicSqlSupport.id, isEqualTo(Long.valueOf(modelId)))
392+
.where(GroupRecordDynamicSqlSupport.id, isEqualTo(pk))
388393
.and(GroupRecordDynamicSqlSupport.terminationTime, SqlBuilder.isNull())
389394
.build()
390395
.execute() > 0;

src/main/java/ch/ethz/seb/sps/server/datalayer/dao/impl/ScreenshotDataDAOBatis.java

Lines changed: 93 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -113,108 +113,105 @@ public Result<Collection<ScreenshotData>> allOf(final Set<Long> pks) {
113113

114114
@Override
115115
@Transactional(readOnly = true)
116-
public Result<Collection<ScreenshotData>> allOfSession(final String sessionUUID) {
116+
public Result<Collection<ScreenshotDataRecord>> allOfSession(final String sessionUUID) {
117117
return Result.tryCatch(() -> this.screenshotDataRecordMapper.selectByExample()
118118
.where(ScreenshotDataRecordDynamicSqlSupport.sessionUuid, SqlBuilder.isEqualTo(sessionUUID))
119119
.build()
120-
.execute()
121-
.stream()
122-
.map(this::toDomainModel)
123-
.collect(Collectors.toList()));
120+
.execute());
124121
}
125122

126-
@Override
127-
@Transactional(readOnly = true)
128-
public Result<ScreenshotDataRecord> getAt(final String sessionUUID, final Long at) {
129-
130-
System.out.print("******************** getAt called for session: " + sessionUUID + " with at: " + at);
131-
132-
// TODO: this seems to produce performance issues when table is huge. Try to optimize query by reducing the time frame here
133-
return Result.tryCatch(() -> {
134-
ScreenshotDataRecord record = SelectDSL
135-
.selectWithMapper(this.screenshotDataRecordMapper::selectOne,
136-
id,
137-
sessionUuid,
138-
timestamp,
139-
imageFormat,
140-
metaData,
141-
timestamp)
142-
.from(screenshotDataRecord)
143-
.where(ScreenshotDataRecordDynamicSqlSupport.sessionUuid, SqlBuilder.isEqualTo(sessionUUID))
144-
.and(ScreenshotDataRecordDynamicSqlSupport.timestamp, SqlBuilder.isLessThanOrEqualTo(at))
145-
.orderBy(timestamp.descending())
146-
.limit(1)
147-
.build()
148-
.execute();
149-
150-
if (record != null) {
151-
return record;
152-
}
153-
154-
// there is no screenshot at the time of given timestamp. Try to get first image for the session
155-
record = SelectDSL
156-
.selectWithMapper(this.screenshotDataRecordMapper::selectOne,
157-
id,
158-
sessionUuid,
159-
timestamp,
160-
imageFormat,
161-
metaData,
162-
timestamp)
163-
.from(screenshotDataRecord)
164-
.where(ScreenshotDataRecordDynamicSqlSupport.sessionUuid, SqlBuilder.isEqualTo(sessionUUID))
165-
.orderBy(timestamp)
166-
.limit(1)
167-
.build()
168-
.execute();
169-
170-
// still no screenshot... seems that there are none at this time
171-
if (record == null) {
172-
throw new NoResourceFoundException(EntityType.SCREENSHOT_DATA, sessionUUID);
173-
}
174-
175-
return record;
176-
});
177-
}
178-
179-
@Override
180-
@Transactional(readOnly = true)
181-
public Result<Long> getIdAt(final String sessionUUID, final Long at) {
182-
return Result.tryCatch(() -> {
183-
184-
System.out.println("******************** getIdAt called for session: " + sessionUUID + " with at: " + at);
185-
186-
List<Long> result = SelectDSL
187-
.selectWithMapper(this.screenshotDataRecordMapper::selectIds, id, timestamp)
188-
.from(screenshotDataRecord)
189-
.where(ScreenshotDataRecordDynamicSqlSupport.sessionUuid, SqlBuilder.isEqualTo(sessionUUID))
190-
.and(ScreenshotDataRecordDynamicSqlSupport.timestamp, SqlBuilder.isLessThanOrEqualTo(at))
191-
.orderBy(timestamp.descending())
192-
.limit(1)
193-
.build()
194-
.execute();
195-
196-
if (result != null && !result.isEmpty()) {
197-
return result.get(0);
198-
}
199-
200-
// there is no screenshot at the time of given timestamp. Try to get first image for the session
201-
result = SelectDSL
202-
.selectWithMapper(this.screenshotDataRecordMapper::selectIds, id, timestamp)
203-
.from(screenshotDataRecord)
204-
.where(ScreenshotDataRecordDynamicSqlSupport.sessionUuid, SqlBuilder.isEqualTo(sessionUUID))
205-
.orderBy(timestamp)
206-
.limit(1)
207-
.build()
208-
.execute();
209-
210-
// still no screenshot... seems that there are none at this time
211-
if (result == null || result.isEmpty()) {
212-
throw new NoResourceFoundException(EntityType.SCREENSHOT_DATA, sessionUUID);
213-
}
123+
// @Override
124+
// @Transactional(readOnly = true)
125+
// public Result<ScreenshotDataRecord> getAt(final String sessionUUID, final Long at) {
126+
//
127+
// System.out.print("******************** getAt called for session: " + sessionUUID + " with at: " + at);
128+
//
129+
// // TODO: this seems to produce performance issues when table is huge. Try to optimize query by reducing the time frame here
130+
// return Result.tryCatch(() -> {
131+
// ScreenshotDataRecord record = SelectDSL
132+
// .selectWithMapper(this.screenshotDataRecordMapper::selectOne,
133+
// id,
134+
// sessionUuid,
135+
// timestamp,
136+
// imageFormat,
137+
// metaData,
138+
// timestamp)
139+
// .from(screenshotDataRecord)
140+
// .where(ScreenshotDataRecordDynamicSqlSupport.sessionUuid, SqlBuilder.isEqualTo(sessionUUID))
141+
// .and(ScreenshotDataRecordDynamicSqlSupport.timestamp, SqlBuilder.isLessThanOrEqualTo(at))
142+
// .orderBy(timestamp.descending())
143+
// .limit(1)
144+
// .build()
145+
// .execute();
146+
//
147+
// if (record != null) {
148+
// return record;
149+
// }
150+
//
151+
// // there is no screenshot at the time of given timestamp. Try to get first image for the session
152+
// record = SelectDSL
153+
// .selectWithMapper(this.screenshotDataRecordMapper::selectOne,
154+
// id,
155+
// sessionUuid,
156+
// timestamp,
157+
// imageFormat,
158+
// metaData,
159+
// timestamp)
160+
// .from(screenshotDataRecord)
161+
// .where(ScreenshotDataRecordDynamicSqlSupport.sessionUuid, SqlBuilder.isEqualTo(sessionUUID))
162+
// .orderBy(timestamp)
163+
// .limit(1)
164+
// .build()
165+
// .execute();
166+
//
167+
// // still no screenshot... seems that there are none at this time
168+
// if (record == null) {
169+
// throw new NoResourceFoundException(EntityType.SCREENSHOT_DATA, sessionUUID);
170+
// }
171+
//
172+
// return record;
173+
// });
174+
// }
214175

215-
return result.get(0);
216-
});
217-
}
176+
// @Override
177+
// @Transactional(readOnly = true)
178+
// public Result<Long> getIdAt(final String sessionUUID, final Long at) {
179+
// return Result.tryCatch(() -> {
180+
//
181+
// System.out.println("******************** getIdAt called for session: " + sessionUUID + " with at: " + at);
182+
//
183+
// List<Long> result = SelectDSL
184+
// .selectWithMapper(this.screenshotDataRecordMapper::selectIds, id, timestamp)
185+
// .from(screenshotDataRecord)
186+
// .where(ScreenshotDataRecordDynamicSqlSupport.sessionUuid, SqlBuilder.isEqualTo(sessionUUID))
187+
// .and(ScreenshotDataRecordDynamicSqlSupport.timestamp, SqlBuilder.isLessThanOrEqualTo(at))
188+
// .orderBy(timestamp.descending())
189+
// .limit(1)
190+
// .build()
191+
// .execute();
192+
//
193+
// if (result != null && !result.isEmpty()) {
194+
// return result.get(0);
195+
// }
196+
//
197+
// // there is no screenshot at the time of given timestamp. Try to get first image for the session
198+
// result = SelectDSL
199+
// .selectWithMapper(this.screenshotDataRecordMapper::selectIds, id, timestamp)
200+
// .from(screenshotDataRecord)
201+
// .where(ScreenshotDataRecordDynamicSqlSupport.sessionUuid, SqlBuilder.isEqualTo(sessionUUID))
202+
// .orderBy(timestamp)
203+
// .limit(1)
204+
// .build()
205+
// .execute();
206+
//
207+
// // still no screenshot... seems that there are none at this time
208+
// if (result == null || result.isEmpty()) {
209+
// throw new NoResourceFoundException(EntityType.SCREENSHOT_DATA, sessionUUID);
210+
// }
211+
//
212+
// return result.get(0);
213+
// });
214+
// }
218215

219216
// @Override
220217
// @Transactional(readOnly = true)

src/main/java/ch/ethz/seb/sps/server/datalayer/dao/impl/SessionDAOBatis.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,9 +658,14 @@ public boolean isActive(String modelId) {
658658
return false;
659659
}
660660

661+
final Long pk = modelIdToPK(modelId);
662+
if (pk == null) {
663+
return false;
664+
}
665+
661666
return this.sessionRecordMapper
662667
.countByExample()
663-
.where(ExamRecordDynamicSqlSupport.id, isEqualTo(Long.valueOf(modelId)))
668+
.where(ExamRecordDynamicSqlSupport.id, isEqualTo(pk))
664669
.and(ExamRecordDynamicSqlSupport.terminationTime, SqlBuilder.isNull())
665670
.build()
666671
.execute() > 0;

src/main/java/ch/ethz/seb/sps/server/datalayer/dao/impl/UserDAOBatis.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,13 @@ public boolean isActive(final String modelId) {
134134
return false;
135135
}
136136

137+
final Long pk = modelIdToPK(modelId);
138+
if (pk == null) {
139+
return false;
140+
}
141+
137142
return this.userRecordMapper.countByExample()
138-
.where(UserRecordDynamicSqlSupport.id, isEqualTo(Long.valueOf(modelId)))
143+
.where(UserRecordDynamicSqlSupport.id, isEqualTo(pk))
139144
.and(UserRecordDynamicSqlSupport.terminationTime, SqlBuilder.isNull())
140145
.build()
141146
.execute() > 0;

src/main/java/ch/ethz/seb/sps/server/servicelayer/LiveProctoringCacheService.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,6 @@ public interface LiveProctoringCacheService {
2525
* @param sessionUUID The live session UUID
2626
* @return PK id of the last screenshot_data row if available or -1 if there is no screenshot yet or null if there is no slot for the given sessionUUID*/
2727
Long getLatestSSDataId(String sessionUUID, boolean createSlot);
28-
29-
// /** Creates a new cache slot for given session. Usually called when session is created
30-
// *
31-
// * @param sessionUUID Session UUID to create a live cache slot for
32-
// * @return Result refer to given sessionUUID or to an error when happened */
33-
// Result<String> createCacheSlot(String sessionUUID);
34-
//
35-
// /** Deletes a cache slot for a given session. Usually called when session is closed
36-
// *
37-
// * @param sessionUUID Session UUID to create a live cache slot for
38-
// * @return Result refer to given sessionUUID or to an error when happened */
39-
// Result<String> deleteCacheSlot(String sessionUUID);
4028

4129
/** Called by the batch store services to update latest cache entries on storage
4230
* @param batch The batch with the latest screenshot_data ids */

0 commit comments

Comments
 (0)