@@ -126,6 +126,9 @@ public Result<Collection<ScreenshotData>> allOfSession(final String sessionUUID)
126126 @ Override
127127 @ Transactional (readOnly = true )
128128 public Result <ScreenshotDataRecord > getAt (final String sessionUUID , final Long at ) {
129+
130+ System .out .print ("******************** getAt called for session: " + sessionUUID + " with at: " + at );
131+
129132 // TODO: this seems to produce performance issues when table is huge. Try to optimize query by reducing the time frame here
130133 return Result .tryCatch (() -> {
131134 ScreenshotDataRecord record = SelectDSL
@@ -178,6 +181,8 @@ record = SelectDSL
178181 public Result <Long > getIdAt (final String sessionUUID , final Long at ) {
179182 return Result .tryCatch (() -> {
180183
184+ System .out .println ("******************** getIdAt called for session: " + sessionUUID + " with at: " + at );
185+
181186 List <Long > result = SelectDSL
182187 .selectWithMapper (this .screenshotDataRecordMapper ::selectIds , id , timestamp )
183188 .from (screenshotDataRecord )
@@ -211,28 +216,33 @@ public Result<Long> getIdAt(final String sessionUUID, final Long at) {
211216 });
212217 }
213218
214- @ Override
215- @ Transactional (readOnly = true )
216- public Result <Long > getLatestImageId (final String sessionUUID ) {
217- return Result .tryCatch (() -> {
218-
219- final List <Long > execute = SelectDSL
220- .selectDistinctWithMapper (this .screenshotDataRecordMapper ::selectIds , id , timestamp )
221- .from (screenshotDataRecord )
222- .where (ScreenshotDataRecordDynamicSqlSupport .sessionUuid , SqlBuilder .isEqualTo (sessionUUID ))
223- .orderBy (timestamp .descending ())
224- .limit (1 )
225- .build ()
226- .execute ();
227-
228- return execute .get (0 );
229- });
230- }
219+ // @Override
220+ // @Transactional(readOnly = true)
221+ // public Result<Long> getLatestImageId(final String sessionUUID) {
222+ // return Result.tryCatch(() -> {
223+ //
224+ // System.out.println("******************** getLatestImageId called for session: " + sessionUUID );
225+ //
226+ // final List<Long> execute = SelectDSL
227+ // .selectDistinctWithMapper(this.screenshotDataRecordMapper::selectIds, id, timestamp)
228+ // .from(screenshotDataRecord)
229+ // .where(ScreenshotDataRecordDynamicSqlSupport.sessionUuid, SqlBuilder.isEqualTo(sessionUUID))
230+ // .orderBy(timestamp.descending())
231+ // .limit(1)
232+ // .build()
233+ // .execute();
234+ //
235+ // return execute.get(0);
236+ // });
237+ // }
231238
232239 @ Override
233240 @ Transactional (readOnly = true )
234241 public Result <ScreenshotDataRecord > getLatest (final String sessionUUID ) {
235242 return Result .tryCatch (() -> {
243+
244+ System .out .println ("******************** getLatest called for session: " + sessionUUID );
245+
236246 final ScreenshotDataRecord latestScreenshotDataRec = getLatestScreenshotDataRec (sessionUUID );
237247 if (latestScreenshotDataRec == null ) {
238248 throw new NoResourceFoundException (EntityType .SCREENSHOT_DATA , sessionUUID );
@@ -242,42 +252,60 @@ public Result<ScreenshotDataRecord> getLatest(final String sessionUUID) {
242252 }
243253
244254 @ Override
245- @ Transactional (readOnly = true )
246- public Result <Map <String , ScreenshotDataRecord >> allLatestIn (final List <String > sessionUUIDs ) {
255+ public Result <Map <String , ScreenshotDataRecord >> allOfMappedToSession (final List <Long > pks ) {
247256 return Result .tryCatch (() -> {
248- if (sessionUUIDs == null || sessionUUIDs .isEmpty ()) {
257+
258+ if (pks == null || pks .isEmpty ()) {
249259 return Collections .emptyMap ();
250260 }
251261
252- // NOTE: This was not working as expected since limit does not work with group (groupBy)
253- // return SelectDSL
254- // .selectWithMapper(this.screenshotDataRecordMapper::selectMany,
255- // id,
256- // sessionUuid,
257- // timestamp,
258- // imageFormat,
259- // metaData)
260- // .from(screenshotDataRecord)
261- // .where(ScreenshotDataRecordDynamicSqlSupport.sessionUuid, SqlBuilder.isIn(sessionUUIDs))
262- // .groupBy(ScreenshotDataRecordDynamicSqlSupport.sessionUuid)
263- // .orderBy(timestamp.descending())
264- // .limit(1)
265- // .build()
266- // .execute()
267- // .stream()
268- // .collect(Collectors.toMap(r -> r.getSessionUuid(), Function.identity()));
269-
270- // NOTE: For now we use a less efficient version that uses getLatest(final String sessionUUID) for
271- // all requested sessions but in the future we should solve this problem on DB layer
272- return sessionUUIDs .stream ()
273- .map (this ::getLatestScreenshotDataRec )
274- .filter (Objects ::nonNull )
275- .collect (Collectors .toMap (
276- ScreenshotDataRecord ::getSessionUuid ,
277- Function .identity ()));
262+ return screenshotDataRecordMapper
263+ .selectByExample ()
264+ .where (id , isIn (pks ))
265+ .build ()
266+ .execute ()
267+ .stream ()
268+ .collect (Collectors .toMap (r -> r .getSessionUuid (), Function .identity ()));
278269 });
279270 }
280271
272+ // @Override
273+ // @Transactional(readOnly = true)
274+ // public Result<Map<String, ScreenshotDataRecord>> allLatestIn(final List<String> sessionUUIDs) {
275+ // return Result.tryCatch(() -> {
276+ // if (sessionUUIDs == null || sessionUUIDs.isEmpty()) {
277+ // return Collections.emptyMap();
278+ // }
279+ //
280+ // // NOTE: This was not working as expected since limit does not work with group (groupBy)
281+ //// return SelectDSL
282+ //// .selectWithMapper(this.screenshotDataRecordMapper::selectMany,
283+ //// id,
284+ //// sessionUuid,
285+ //// timestamp,
286+ //// imageFormat,
287+ //// metaData)
288+ //// .from(screenshotDataRecord)
289+ //// .where(ScreenshotDataRecordDynamicSqlSupport.sessionUuid, SqlBuilder.isIn(sessionUUIDs))
290+ //// .groupBy(ScreenshotDataRecordDynamicSqlSupport.sessionUuid)
291+ //// .orderBy(timestamp.descending())
292+ //// .limit(1)
293+ //// .build()
294+ //// .execute()
295+ //// .stream()
296+ //// .collect(Collectors.toMap(r -> r.getSessionUuid(), Function.identity()));
297+ //
298+ // // NOTE: For now we use a less efficient version that uses getLatest(final String sessionUUID) for
299+ // // all requested sessions but in the future we should solve this problem on DB layer
300+ // return sessionUUIDs.stream()
301+ // .map(this::getLatestScreenshotDataRec)
302+ // .filter(Objects::nonNull)
303+ // .collect(Collectors.toMap(
304+ // ScreenshotDataRecord::getSessionUuid,
305+ // Function.identity()));
306+ // });
307+ // }
308+
281309 @ Override
282310 @ Transactional (readOnly = true )
283311 public Result <Collection <ScreenshotData >> allMatching (
@@ -709,7 +737,15 @@ public Result<List<Long>> getTimestampListForApplicationSearch(
709737 });
710738 }
711739
740+ @ Override
741+ public Result <ScreenshotDataRecord > recordByPK (Long pk ) {
742+ return Result .tryCatch (() -> this .screenshotDataRecordMapper .selectByPrimaryKey (pk ));
743+ }
744+
712745 private ScreenshotDataRecord getLatestScreenshotDataRec (final String sessionUUID ) {
746+
747+ System .out .println ("******************** getLatestScreenshotDataRec called for session: " + sessionUUID );
748+
713749 return SelectDSL
714750 .selectWithMapper (this .screenshotDataRecordMapper ::selectOne ,
715751 id ,
0 commit comments