on 68a32d7 help sign in
3 files changed+3−21
since splitsnapshots
unifiedsplit
Sources/App/Models/SafeDict.swift+3−11 Sources/App/routes.swift−4 Sources/Run/main.swift−6
Sources/App/Models/SafeDict.swift+3−11
@@ -7,14 +7,6 @@
77
88import Foundation
99
10−func getRandomNum(_ min: Int, _ max: Int) -> Int {
11− #if os(Linux)
12− return Int(random() % max) + min
13− #else
14− return Int(arc4random_uniform(UInt32(max)) + UInt32(min))
15− #endif
16−}
17−
1810struct SafeDict<Key: Hashable, Value> {
1911 private var queue = DispatchQueue(label: "soy.iko.safeDict.queue", attributes: .concurrent)
2012
@@ -41,9 +33,9 @@ struct SafeDict<Key: Hashable, Value> {
4133 mutating func removeRandom() -> Key? {
4234 var key: Key?
4335 queue.sync(flags: .barrier) {
44− if dict.count > 0 {
45− key = Array(dict.keys)[getRandomNum(0, dict.count)]
46− dict[key!] = nil
36+ key = dict.keys.randomElement()
37+ if let key = key {
38+ dict[key] = nil
4739 }
4840 }
4941 return key
Sources/App/routes.swift−4
@@ -33,10 +33,6 @@ public func routes(_ router: Router) throws {
3333 }
3434 return post
3535 }
36−
37− router.get("posts") { (req) -> [Post] in
38− return Array(Post.storage.values)
39− }
4036}
4137
4238enum DatabaseError: Error, AbortError {
Sources/Run/main.swift−6
@@ -1,9 +1,3 @@
11import App
22
3−#if os(Linux)
4−import SwiftGlibc
5−srandom(UInt32(time(nil)))
6−#endif
7−
8−
93try app(.detect()).run()