azerphoenix
@azerphoenix
Java Software Engineer

Почему может быть долгий ответ от сервера в Spring REST Repositories?

Здравствуйте!
Имеется Spring Boot приложение. Подключил Spring Rest Repositories. Данные хранятся в БД (MySQL).
Имеется 2 сущности:
Author {
@JsonIgnore
@OneToMany(mappedBy = "author")
List<Book> books = new ArrayList();
}

Book {
@JsonIgnore @ManyToOne
  @JoinColumn(name = "author_id")
  private Author author;
}


Вот, репозиторий:
@Repository
public interface BookRepository extends JpaRepository<Book, Long> {

  List<Book> findAllByAuthor(Author author);
  Page<Book> findAllByAuthor(Author author, Pageable pageable);

}

В файл конфигурации добавлен:
spring.data.rest.basePath=/api
spring.data.rest.defaultPageSize=100


Если обратиться к урлу author
http://localhost:7777/api/authors/1/books
и запросить книги этого автора и если книг довольно много, то запрос выполняется довольно долго. Мне кажется, что он пытается вернуть все книги этого автора (около 500 000) вместо того, чтобы возвращать их постранично

Почему так происходит и как это устранить?

Вот, скриншоты:
5f3ee1720e02d522525060.png
5f3ee18516b53895958042.png
А дальше при переходе на урл
http://localhost:7777/api/cities/4/features
или
http://localhost:7777/api/cities/4/features?page=1
уже долгий запрос

Вот, лог в show_sql при обращении к вышеуказанным урлам:
Hibernate: select city0_.city_id as city_id1_0_0_, city0_.city_iso_code as city_iso2_0_0_, city0_.city_name as city_nam3_0_0_, city0_.country_id as country_4_0_0_, country1_.country_id as country_1_1_1_, country1_.country_iso_code as country_2_1_1_, country1_.country_name as country_3_1_1_, country1_.map_link as map_link4_1_1_ from cities city0_ left outer join countries country1_ on city0_.country_id=country1_.country_id where city0_.city_id=?
Hibernate: select features0_.city_id as city_id6_4_0_, features0_.feature_id as feature_1_4_0_, features0_.feature_id as feature_1_4_1_, features0_.city_id as city_id6_4_1_, features0_.city_iso_code as city_iso2_4_1_, features0_.country_id as country_7_4_1_, features0_.country_iso_code as country_3_4_1_, features0_.type as type4_4_1_, features0_.wkt as wkt5_4_1_, country1_.country_id as country_1_1_2_, country1_.country_iso_code as country_2_1_2_, country1_.country_name as country_3_1_2_, country1_.map_link as map_link4_1_2_ from features features0_ left outer join countries country1_ on features0_.country_id=country1_.country_id where features0_.city_id=?
  • Вопрос задан
  • 211 просмотров
Пригласить эксперта
Ответы на вопрос 1
Jacen11
@Jacen11
делать пагинацию
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
Bell Integrator Хабаровск
До 400 000 ₽
Bell Integrator Ульяновск
До 400 000 ₽
Bell Integrator Ижевск
До 400 000 ₽
26 апр. 2024, в 06:46
1000 руб./в час
26 апр. 2024, в 05:31
1000 руб./за проект