Skip to content

Commit

Permalink
[FIX] Fixed query performance
Browse files Browse the repository at this point in the history
  • Loading branch information
MathisBurger committed Jul 1, 2024
1 parent 041f4d4 commit 87bda90
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ There are many new features planned. You can find a little roadmap of planned fu
### v1.4.0
- [x] Full UNIT test coverage (services)
- [x] User account system
- [ ] Support Chat for renter
- [x] Support Chat for renter
- [ ] Rental status / statistics about the renter
- [ ] Update mail notifications with favourites
- [ ] Performance calculations (by input of data)
Expand All @@ -74,7 +74,6 @@ There are many new features planned. You can find a little roadmap of planned fu
- [ ] Mail templates to send
- [ ] Rentability calculations
- [ ] Auto collect market value change data
- [ ] Optimize chat query

### Not planned yet
- [ ] Add balance sheet calculation
Expand Down
16 changes: 1 addition & 15 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
# Handles general intra-version TODOs

### Renter support chat

- [x] Create renter on object
- [x] Delete renter from object
- [x] Add general chat feature (internal chat)
- [x] Fetch messages that are more far away...
- [x] Create new chats
- [x] Functionality to read messages
- [x] Display amount of unread messages
- [x] Websocket chat integration
- [x] Create renter login & user accounts
- [x] Create rental support chats (all allowed users can communicate with single renter => Renter only has one chat with all of them
- [x] Delete renter chat on renter delete

### Rental / Renter status and statistics

- [ ] Ability to disable renter account
- [ ] On renter remove open modal to choose whether delete completely or just unassign renter from object
- [ ] On renter remove open modal to choose whether delete completely or just unassign renter from object => disable account
- [ ] Renter dashboard with ability to see statistics about current rental relation
- [ ] Collect rental data on renter and display in renter view
23 changes: 23 additions & 0 deletions src/main/kotlin/de/immowealth/repository/ChatRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package de.immowealth.repository

import de.immowealth.entity.*
import jakarta.enterprise.context.ApplicationScoped
import jakarta.persistence.Query
import jakarta.persistence.criteria.Join
import jakarta.persistence.criteria.Predicate

/**
* The repository that handles chats
Expand Down Expand Up @@ -32,8 +35,28 @@ class ChatRepository : AbstractRepository<Chat>() {
for (ignored in ignore) {
inClause.value(ignored);
}
val realEstateJoin = root.join<Chat, Tenant>("realEstateObject");
var tenantCondition: Predicate? = null;
if (user.tenant === null) {
tenantCondition = cb.isNull(realEstateJoin.get<Tenant?>("tenant"));
} else {
tenantCondition = cb.equal(realEstateJoin.get<Tenant?>("tenant"), user.tenant);
}
var renterCondition: Predicate? = null;
if (user.renter !== null) {
val renters = realEstateJoin.get<List<Renter>>("renters");
renterCondition = cb.isMember(user.renter!!, renters);
}

var finalMidCondition: Predicate? = null;
if (renterCondition !== null) {
finalMidCondition = cb.or(tenantCondition, renterCondition)
} else {
finalMidCondition = tenantCondition;
}
val finalCondition = cb.and(
cb.equal(root.get<Boolean>("isRenterChat"), true),
finalMidCondition,
cb.not(inClause)
);
cq.select(root).where(finalCondition);
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/de/immowealth/service/RenterService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class RenterService : AbstractService() {
user.username = input.username;
user.password = BcryptUtil.bcryptHash(input.password)
user.email = input.email;
user.renter = renter;
user.roles = mutableListOf(UserRoles.RENTER)
renter.user = user;
this.denyUnlessGranted(RenterVoter.CREATE, renter);
Expand Down

0 comments on commit 87bda90

Please sign in to comment.