Оптимизировано получение пакетов

This commit is contained in:
sshkurov
2022-01-31 21:52:11 +03:00
parent 3d06b25d7a
commit f5dcdf12ab
4 changed files with 21 additions and 14 deletions

View File

@@ -7,10 +7,12 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.http.HttpStatus;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.server.ResponseStatusException;
import ru.serega6531.packmate.model.*;
import ru.serega6531.packmate.model.enums.PatternActionType;
import ru.serega6531.packmate.model.enums.PatternDirectionType;
@@ -242,8 +244,10 @@ public class StreamService {
return saved;
}
public Optional<Stream> find(long id) {
return repository.findById(id);
public List<Packet> getPackets(long streamId) {
return repository.getStreamWithPackets(streamId)
.map(Stream::getPackets)
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
}
/**