Merge pull request #117 from rbkmoney/ft/sql-optim

Optimize shop contract and contractor batch update
This commit is contained in:
Kostya 2020-04-17 18:04:42 +03:00 committed by GitHub
commit e7ba8785a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 15 deletions

View File

@ -84,11 +84,15 @@ public class ContractDaoImpl extends AbstractGenericDao implements ContractDao {
@Override
public void switchCurrent(List<String> ids, String partyId) throws DaoException {
ids.forEach(id ->
this.getNamedParameterJdbcTemplate()
.update("update nw.contract set current = false where contract_id =:contract_id and party_id=:party_id and current;" +
"update nw.contract set current = true where id = (select max(id) from nw.contract where contract_id =:contract_id and party_id=:party_id);",
new MapSqlParameterSource(Map.of("contract_id", id, "party_id", partyId))));
.update("update nw.contract set current = false where contract_id in(:contract_ids) and party_id=:party_id and current;" +
"update nw.contract set current = true where id in(" +
" SELECT max(id)" +
" FROM nw.contract" +
" where contract_id in (:contract_ids)" +
" and party_id=:party_id" +
" group by contract_id, party_id);",
new MapSqlParameterSource(Map.of("contract_ids", ids, "party_id", partyId)));
}
@Override

View File

@ -83,11 +83,15 @@ public class ContractorDaoImpl extends AbstractGenericDao implements ContractorD
@Override
public void switchCurrent(List<String> ids, String partyId) throws DaoException {
ids.forEach(id ->
this.getNamedParameterJdbcTemplate()
.update("update nw.contractor set current = false where contractor_id =:contractor_id and party_id=:party_id and current;" +
"update nw.contractor set current = true where id = (select max(id) from nw.contractor where contractor_id =:contractor_id and party_id=:party_id);",
new MapSqlParameterSource(Map.of("contractor_id", id, "party_id", partyId))));
.update("update nw.contractor set current = false where contractor_id in(:contractor_ids) and party_id=:party_id and current;" +
"update nw.contractor set current = true where id in(" +
" SELECT max(id)" +
" FROM nw.contractor" +
" where contractor_id in (:contractor_ids)" +
" and party_id=:party_id" +
" group by contractor_id, party_id);",
new MapSqlParameterSource(Map.of("contractor_ids", ids, "party_id", partyId)));
}
@Override

View File

@ -85,11 +85,15 @@ public class ShopDaoImpl extends AbstractGenericDao implements ShopDao {
@Override
public void switchCurrent(List<String> ids, String partyId) throws DaoException {
ids.forEach(id ->
this.getNamedParameterJdbcTemplate()
.update("update nw.shop set current = false where shop_id =:shop_id and party_id=:party_id and current;" +
"update nw.shop set current = true where id = (select max(id) from nw.shop where shop_id =:shop_id and party_id=:party_id);",
new MapSqlParameterSource(Map.of("shop_id", id, "party_id", partyId))));
.update("update nw.shop set current = false where shop_id in(:shop_ids) and party_id=:party_id and current;" +
"update nw.shop set current = true where id in(" +
" SELECT max(id)" +
" FROM nw.shop" +
" where shop_id in (:shop_ids)" +
" and party_id=:party_id" +
" group by shop_id, party_id);",
new MapSqlParameterSource(Map.of("shop_ids", ids, "party_id", partyId)));
}
@Override