-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
T-14 Fix encoded url on server error: - Fix encoded url error - Add decoder init, remove replacingPercentEncoding from ProductsController - Add cache cleaning to Dockerfile - Add product available count scheduled restore job
- Loading branch information
Showing
6 changed files
with
85 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...p/Helpers/OrderJobs/RestoreAvailableProductCountJob/RestoreAvailableProductCountJob.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// RestoreAvailableProductCountJob.swift | ||
// | ||
// | ||
// Created by Artem Mayer on 08.09.2024. | ||
// | ||
|
||
import Vapor | ||
import Fluent | ||
import Queues | ||
import FluentSQL | ||
|
||
struct RestoreAvailableProductCountJob: AsyncScheduledJob { | ||
|
||
static let rawSQLQuery: SQLQueryString = "SELECT * FROM AVAILABILITY_INFOS_COPY" | ||
|
||
func run(context: QueueContext) async throws { | ||
|
||
let sqlDatabase = context.application.db as! SQLDatabase | ||
let _availabilityInfosCopy = try await sqlDatabase.raw(Self.rawSQLQuery) | ||
.all(decodingFluent: AvailabilityInfo.self) | ||
let infosCopy = Set<AvailabilityInfo>(_availabilityInfosCopy) | ||
|
||
try await context.application.db.transaction { transaction in | ||
|
||
let availabilityInfos = try await AvailabilityInfo.query(on: transaction).all() | ||
|
||
try await availabilityInfos.asyncForEach { info in | ||
|
||
if let updateCount = updatingCount(info: info, with: infosCopy) { | ||
info.count = updateCount | ||
try await info.update(on: transaction) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private func updatingCount(info: AvailabilityInfo, with infosCopy: Set<AvailabilityInfo>) -> Int? { | ||
guard let infoCopyIndex = infosCopy.firstIndex(of: info) else { return nil } | ||
|
||
let infoCopyCount = infosCopy[infoCopyIndex].count | ||
return info.id == infosCopy[infoCopyIndex].id && info.count < infoCopyCount ? infoCopyCount : nil | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters