update 20.10.2025

This commit is contained in:
Kevin Adametz 2025-10-20 17:42:08 +02:00
parent 8ccd81b770
commit a67740d6ef
612 changed files with 84540 additions and 4008 deletions

View file

@ -24,10 +24,12 @@ class BusinessUserRepository
{
$this->month = $month;
$this->year = $year;
$date = Carbon::parse($year.'-'.$month.'-1');
$date = Carbon::parse($year . '-' . $month . '-1');
$this->startDate = $date->format('Y-m-d H:i:s');
$this->endDate = $date->endOfMonth()->format('Y-m-d H:i:s');
\Log::info("BusinessUserRepository: Start Date: " . $this->startDate);
\Log::info("BusinessUserRepository: End Date: " . $this->endDate);
}
/**
@ -36,27 +38,26 @@ class BusinessUserRepository
public function getRootUsers(): Collection
{
$cacheKey = "root_users_{$this->month}_{$this->year}";
return cache()->remember($cacheKey, 3600, function() {
\Log::info("BusinessUserRepository: Loading root users from database (cache miss)");
//root hat keinen parent m_sponsor, hat
return cache()->remember($cacheKey, 3600, function () {
return User::with([
'account',
'account',
'user_level',
'userBusiness' => function($query) {
'userBusiness' => function ($query) {
$query->where('month', $this->month)
->where('year', $this->year);
->where('year', $this->year);
}
])
->select('users.*')
->where('users.deleted_at', '=', null)
->where('users.id', '!=', 1)
->where('users.admin', '<', 4)
->where('users.m_level', '!=', null)
->where('users.m_sponsor', '=', null)
->where('users.payment_account', '!=', null)
->where('users.active_date', '<=', $this->endDate)
->get();
->select('users.*')
->where('users.deleted_at', '=', null)
->where('users.id', '!=', 1)
->where('users.admin', '<', 4)
->where('users.m_level', '!=', null)
->where('users.m_sponsor', '=', null)
->where('users.payment_account', '!=', null)
->where('users.active_date', '<=', $this->endDate)
->where('users.payment_account', '>', $this->endDate)
->get();
});
}
@ -66,19 +67,19 @@ class BusinessUserRepository
public function getParentlessUsers(array $excludeUserIds = []): LazyCollection
{
$query = User::with([
'account',
'account',
'user_level',
'userBusiness' => function($query) {
'userBusiness' => function ($query) {
$query->where('month', $this->month)
->where('year', $this->year);
->where('year', $this->year);
}
])
->select('users.*')
->where('users.deleted_at', '=', null)
->where('users.id', '!=', 1)
->where('users.admin', '<', 4)
->where('users.payment_account', '!=', null)
->where('users.active_date', '<=', $this->endDate);
->select('users.*')
->where('users.deleted_at', '=', null)
->where('users.id', '!=', 1)
->where('users.admin', '<', 4)
->where('users.payment_account', '!=', null)
->where('users.active_date', '<=', $this->endDate);
if (!empty($excludeUserIds)) {
$query->whereNotIn('users.id', $excludeUserIds);
@ -93,16 +94,16 @@ class BusinessUserRepository
public function getUserWithRelations(int $userId): ?User
{
$cacheKey = "user_relations_{$userId}_{$this->month}_{$this->year}";
return cache()->remember($cacheKey, 1800, function() use ($userId) {
return cache()->remember($cacheKey, 1800, function () use ($userId) {
\Log::debug("BusinessUserRepository: Loading user {$userId} with relations (cache miss)");
return User::with([
'account',
'account',
'user_level',
'userBusiness' => function($query) {
'userBusiness' => function ($query) {
$query->where('month', $this->month)
->where('year', $this->year);
->where('year', $this->year);
}
])->find($userId);
});
@ -114,7 +115,7 @@ class BusinessUserRepository
public function getSponsorForUser(int $userId): ?User
{
$user = $this->getUserWithRelations($userId);
if (!$user || !$user->m_sponsor) {
return null;
}
@ -128,10 +129,10 @@ class BusinessUserRepository
public function getStoredStructure(): ?UserBusinessStructure
{
$cacheKey = "stored_structure_{$this->month}_{$this->year}";
return cache()->remember($cacheKey, 7200, function() {
return cache()->remember($cacheKey, 7200, function () {
\Log::debug("BusinessUserRepository: Loading stored structure (cache miss)");
$structure = UserBusinessStructure::where('year', $this->year)
->where('month', $this->month)
->first();
@ -167,32 +168,48 @@ class BusinessUserRepository
{
foreach ($structure as $item) {
$userIds[] = $item->user_id;
if (isset($item->parents) && is_array($item->parents)) {
$this->extractUserIdsFromStructure($item->parents, $userIds);
}
}
}
/**
* Löscht alle Cache-Einträge für den aktuellen Monat/Jahr
*/
public function clearCache(): void
{
$cacheKeys = [
"root_users_{$this->month}_{$this->year}",
"stored_structure_{$this->month}_{$this->year}"
];
foreach ($cacheKeys as $key) {
cache()->forget($key);
\Log::info("BusinessUserRepository: Cache cleared for key: {$key}");
}
}
/**
* Batch-Loading für User-Kollektionen
*/
public function loadUsersInBatches(array $userIds, int $batchSize = 100): \Generator
{
$chunks = array_chunk($userIds, $batchSize);
foreach ($chunks as $chunk) {
yield User::with([
'account',
'account',
'user_level',
'userBusiness' => function($query) {
'userBusiness' => function ($query) {
$query->where('month', $this->month)
->where('year', $this->year);
->where('year', $this->year);
}
])
->whereIn('id', $chunk)
->get()
->keyBy('id');
->whereIn('id', $chunk)
->get()
->keyBy('id');
}
}
}
}