Optimize falukantService and DirectorInfo component for improved performance and user experience
- Refactored proposal handling in falukantService to load existing proposals before cleaning expired ones, reducing unnecessary database queries. - Enhanced fetchProposals method with explicit joins for better performance and added a limit to avoid excessive data retrieval. - Updated DirectorInfo component to reload data after hiring a director, ensuring the UI reflects the latest information.
This commit is contained in:
@@ -2412,11 +2412,20 @@ class FalukantService extends BaseService {
|
|||||||
throw new Error('Branch not found or does not belong to the user');
|
throw new Error('Branch not found or does not belong to the user');
|
||||||
}
|
}
|
||||||
const { falukantUserId, regionId } = branch;
|
const { falukantUserId, regionId } = branch;
|
||||||
await this.deleteExpiredProposals();
|
|
||||||
|
// OPTIMIERUNG: Erst Proposals laden, dann nur bei Bedarf bereinigen
|
||||||
|
// Dies vermeidet unnötige DELETE-Queries bei jedem Aufruf
|
||||||
const existingProposals = await this.fetchProposals(falukantUserId, regionId);
|
const existingProposals = await this.fetchProposals(falukantUserId, regionId);
|
||||||
if (existingProposals.length > 0) {
|
if (existingProposals.length > 0) {
|
||||||
|
// Nur bereinigen, wenn wir Proposals haben (im Hintergrund, nicht blockierend)
|
||||||
|
this.deleteExpiredProposals().catch(err =>
|
||||||
|
console.error('[getDirectorProposals] Error cleaning expired proposals:', err)
|
||||||
|
);
|
||||||
return this.formatProposals(existingProposals);
|
return this.formatProposals(existingProposals);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wenn keine Proposals vorhanden sind, bereinigen wir vor der Generierung
|
||||||
|
await this.deleteExpiredProposals();
|
||||||
await this.generateProposals(falukantUserId, regionId);
|
await this.generateProposals(falukantUserId, regionId);
|
||||||
const newProposals = await this.fetchProposals(falukantUserId, regionId);
|
const newProposals = await this.fetchProposals(falukantUserId, regionId);
|
||||||
return this.formatProposals(newProposals);
|
return this.formatProposals(newProposals);
|
||||||
@@ -2434,6 +2443,8 @@ class FalukantService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fetchProposals(falukantUserId, regionId) {
|
async fetchProposals(falukantUserId, regionId) {
|
||||||
|
// OPTIMIERUNG: Query mit expliziten Joins und required: true für bessere Performance
|
||||||
|
// required: true sorgt für INNER JOIN statt LEFT JOIN, was schneller ist
|
||||||
return DirectorProposal.findAll({
|
return DirectorProposal.findAll({
|
||||||
where: { employerUserId: falukantUserId },
|
where: { employerUserId: falukantUserId },
|
||||||
include: [
|
include: [
|
||||||
@@ -2442,20 +2453,40 @@ class FalukantService extends BaseService {
|
|||||||
as: 'character',
|
as: 'character',
|
||||||
attributes: ['firstName', 'lastName', 'birthdate', 'titleOfNobility', 'gender'],
|
attributes: ['firstName', 'lastName', 'birthdate', 'titleOfNobility', 'gender'],
|
||||||
where: { regionId },
|
where: { regionId },
|
||||||
|
required: true, // INNER JOIN für bessere Performance
|
||||||
include: [
|
include: [
|
||||||
{ model: FalukantPredefineFirstname, as: 'definedFirstName' },
|
{
|
||||||
{ model: FalukantPredefineLastname, as: 'definedLastName' },
|
model: FalukantPredefineFirstname,
|
||||||
{ model: TitleOfNobility, as: 'nobleTitle' },
|
as: 'definedFirstName',
|
||||||
|
required: false // LEFT JOIN, da optional
|
||||||
|
},
|
||||||
|
{
|
||||||
|
model: FalukantPredefineLastname,
|
||||||
|
as: 'definedLastName',
|
||||||
|
required: false // LEFT JOIN, da optional
|
||||||
|
},
|
||||||
|
{
|
||||||
|
model: TitleOfNobility,
|
||||||
|
as: 'nobleTitle',
|
||||||
|
required: false // LEFT JOIN, da optional
|
||||||
|
},
|
||||||
{
|
{
|
||||||
model: Knowledge,
|
model: Knowledge,
|
||||||
as: 'knowledges',
|
as: 'knowledges',
|
||||||
|
required: false, // LEFT JOIN, da optional
|
||||||
include: [
|
include: [
|
||||||
{ model: ProductType, as: 'productType' },
|
{
|
||||||
|
model: ProductType,
|
||||||
|
as: 'productType',
|
||||||
|
required: false // LEFT JOIN, da optional
|
||||||
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
// OPTIMIERUNG: Limit setzen, um unnötige Daten zu vermeiden
|
||||||
|
limit: 10,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -181,7 +181,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<NewDirectorDialog ref="newDirectorDialog" />
|
<NewDirectorDialog ref="newDirectorDialog" @directorHired="handleDirectorHired" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@@ -276,6 +276,11 @@ export default {
|
|||||||
this.$refs.newDirectorDialog.open(this.branchId);
|
this.$refs.newDirectorDialog.open(this.branchId);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async handleDirectorHired() {
|
||||||
|
// Nach dem Einstellen eines Direktors die Daten neu laden
|
||||||
|
await this.loadDirector();
|
||||||
|
},
|
||||||
|
|
||||||
async updateDirector() {
|
async updateDirector() {
|
||||||
if (!this.director || this.editIncome == null) return;
|
if (!this.director || this.editIncome == null) return;
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user