mongodb/mongo-swift-driver 233
The official MongoDB driver for Swift
Fight harassment with your squad.
pure Swift BSON library (work in progress)
mailiam/SublimeLinter-contrib-swiftlint 3
SublimeLinter plugin for Swift, using swiftlint.
Advent of Code 2020, in Swift
Demo application using the MongoDB Swift driver
Pull request review commentmongodb/swift-bson
SWIFT-1070 Improve performance of BSONDecoder
public struct BSONDocument { /// The element type of a document: a tuple containing an individual key-value pair. public typealias KeyValuePair = (key: String, value: BSON) - private var storage: BSONDocumentStorage-- /// An unordered set containing the keys in this document.- internal private(set) var keySet: Set<String>+ internal var storage: BSONDocumentStorage internal init(_ elements: [BSON]) { self = BSONDocument(keyValuePairs: elements.enumerated().map { i, element in (String(i), element) }) } internal init(keyValuePairs: [(String, BSON)]) {- self.keySet = Set(keyValuePairs.map { $0.0 })- guard self.keySet.count == keyValuePairs.count else {
good catch. Since this is primarily a concern of dictionary literal initializers, I've moved the validation into them instead of here, since this initializer is also used elsewhere (on potentially un-validated documents in the future).
comment created time in 14 minutes
Pull request review commentmongodb/swift-bson
SWIFT-1070 Improve performance of BSONDecoder
public struct BSONDocument { public func toData() -> Data { Data(self.storage.buffer.readableBytesView) } /// Returns a `Boolean` indicating whether this `BSONDocument` contains the provided key.- public func hasKey(_ key: String) -> Bool { self.keySet.contains(key) }+ public func hasKey(_ key: String) -> Bool {+ (try? BSONDocumentIterator.find(key: key, in: self)) != nil
yep, that's coming in the next one
comment created time in 13 minutes
push eventswift-server/sswg
commit sha 69b8b6d78016ba7cd5192212ded1945fe6931799
update members (#53)
push time in 18 minutes
pull request commentmongodb/swift-bson
SWIFT-1070 Improve performance of BSONDecoder
Oh I forgot to mention: I left off the improvements to BSONDocumentIterator
that make use of the unsafe ByteBuffer
functionality since they are primarily used to speed up withID
/ the insertion benchmarks. The next PR I put up for insertion benchmarks will include those changes.
comment created time in 2 hours
issue closedmongodb/bson-rust
How to add a vector of structs to a document?
Trying to puzzle out the use of a vector of structs, and it doesn't seem to be documented. I presume the following should somehow be made to work.
doc!{ "array_name": vector.iter.map(|entry| ?????).collect() }
Can anyone shed some light on the most idiomatic way to do this?
Edit: If you make a Vec<Document> you can use it in a doc!.
let guessed_grades: Vec<_> = entry.guessed_grades.iter().map(|grades_entry| return doc! { GRADE_NAME: grades_entry.grade_name.clone(), } ).collect();
doc! { GUESSED_GRADES: guessed_grades, }
closed time in 4 hours
jruisecoPull request review commentmongodb/swift-bson
SWIFT-1070 Improve performance of BSONDecoder
extension BSONDocument: Sequence { public func map<T>( _ transform: (Element) throws -> T ) rethrows -> [T] {- try AnySequence(self).map(transform)
This was calling count
a lot, which now requires a full walk over the document. To avoid any issues, I just did a naive manual implementation of map
.
comment created time in 4 hours
Pull request review commentmongodb/swift-bson
SWIFT-1070 Improve performance of BSONDecoder
private class MutableDictionary: BSONValue { internal static let extJSONTypeWrapperKeys: [String] = [] fileprivate static var bsonType: BSONType { .document } - fileprivate var bson: BSON { fatalError("MutableDictionary: BSONValue.bson should be unused") }+ fileprivate var bson: BSON {+ .document(self.toDocument())+ } // rather than using a dictionary, do this so we preserve key orders fileprivate var keys = [String]() fileprivate var values = [BSONValue]()+ fileprivate var latestKeyIndexes = [String: Int]() fileprivate subscript(key: String) -> BSONValue? { get {- guard let index = keys.firstIndex(of: key) else {+ guard let index = self.latestKeyIndexes[key] else { return nil } return self.values[index] } set(newValue) { if let newValue = newValue {+ if let index = self.latestKeyIndexes[key] {+ self.keys.remove(at: index)+ self.values.remove(at: index)+ } self.keys.append(key) self.values.append(newValue)+ self.latestKeyIndexes[key] = self.values.endIndex - 1 } else {- guard let index = keys.firstIndex(of: key) else {+ guard let index = self.latestKeyIndexes[key] else { return }- self.values.remove(at: index) self.keys.remove(at: index)+ self.values.remove(at: index) } } } /// Converts self to a `BSONDocument` with equivalent key-value pairs.- fileprivate func toDocument() throws -> BSONDocument {+ fileprivate func toDocument() -> BSONDocument { var doc = BSONDocument() for i in 0..<self.keys.count { let value = self.values[i]- switch value {- case let val as MutableDictionary:- try doc.set(key: self.keys[i], to: val.toDocument().bson)- case let val as MutableArray:- let array = try val.toBSONArray()- try doc.set(key: self.keys[i], to: array.bson)- default:- try doc.set(key: self.keys[i], to: value.bson)- }+ doc.append(key: self.keys[i], value: value.bson)
since we manually handle overwriting keys in the keyed encoding, we can just append directly without checking prior bytes of the document. This means we don't have to throw
in here anymore and can use the .bson
computed property.
comment created time in 4 hours
Pull request review commentmongodb/swift-bson
SWIFT-1070 Improve performance of BSONDecoder
extension Array: BSONValue where Element == BSON { guard let doc = try BSONDocument.read(from: &buffer).documentValue else { throw BSONError.InternalError(message: "BSON Array cannot be read, failed to get documentValue") }- return .array(doc.values)+ var values: [BSON] = []+ let it = doc.makeIterator()+ while let (_, val) = try it.nextThrowing() {
since BSONDocument.read
doesn't validate anymore, we need to use nextThrowing
to ensure we don't fatalError
. Full validation will be performed in Array.validate
if necessary.
comment created time in 4 hours
PR opened mongodb/swift-bson
SWIFT-1070
This PR improves the performance of the BSONDecoder
. The goal of this PR is simply to match the libbson-based BSON library's performance, so there are still more possible improvements to be done in the future.
We actually ended up improving upon the existing libbson-based BSONDecoder
pretty significantly:
BSON to Native Benchmark Results
benchmark | libbson based median time | target time (1.25x) | post-optimizations |
---|---|---|---|
flat BSON | 6.002 | 7.503 | 2.072 |
deep BSON | 3.463 | 4.329 | 2.683 |
full BSON | 3.876 | 4.845 | 2.017 |
We also improved upon the improved Native to BSON benchmarks we originally saw in swift-bson
:
Native to BSON Benchmark Results
benchmark | libbson based median time | target time (1.25x) | unoptimized swift-bson | post-optimizations |
---|---|---|---|---|
flat BSON | 6.793 | 8.491 | 2.789 | 1.456 |
deep BSON | 4.117 | 5.146 | 3.504 | 2.918 |
full BSON | 6.399 | 7.999 | 4.479 | 2.195 |
pr created time in 4 hours
issue openedmongodb/bson-rust
How to add a vector of structs to a document?
Trying to puzzle out the use of a vector of structs, and it doesn't seem to be documented. I presume the following should somehow be made to work.
doc!{ "array_name": vector.iter.map(|entry| ?????).collect() }
Can anyone shed some light on the most idiomatic way to do this?
created time in 5 hours
startedkneekey23/InAppPurchaseLambda
started time in 7 hours
startedalenakhineika/color-of-berlin-palette
started time in 14 hours
startedcrosire/reshade-shaders
started time in 15 hours
PR opened mongodb/js-bson
Bumps socket.io from 2.3.0 to 2.4.1. <details> <summary>Release notes</summary> <p><em>Sourced from <a href="https://github.com/socketio/socket.io/releases">socket.io's releases</a>.</em></p> <blockquote> <h2>2.4.1</h2> <p>This release reverts the breaking change introduced in <code>2.4.0</code> (<a href="https://github.com/socketio/socket.io/commit/f78a575f66ab693c3ea96ea88429ddb1a44c86c7">https://github.com/socketio/socket.io/commit/f78a575f66ab693c3ea96ea88429ddb1a44c86c7</a>).</p> <p>If you are using Socket.IO v2, you should explicitly allow/disallow cross-origin requests:</p> <ul> <li>without CORS (server and client are served from the same domain):</li> </ul> <pre lang="js"><code>io.origins((req, callback) => { callback(null, req.headers.origin === undefined); // cross-origin requests will not be allowed }); </code></pre> <ul> <li>with CORS (server and client are served from distinct domains):</li> </ul> <pre lang="js"><code>io.origins(["http://localhost:3000"]); // for local development io.origins(["https://example.com"]); </code></pre> <p>In any case, please consider upgrading to Socket.IO v3, where this security issue is now fixed (CORS is disabled by default).</p> <h3>Reverts</h3> <ul> <li>fix(security): do not allow all origins by default (<a href="https://github.com/socketio/socket.io/commit/a1690509470e9dd5559cec4e60908ca6c23e9ba0">a169050</a>)</li> </ul> <h4>Links:</h4> <ul> <li>Diff: <a href="https://github.com/socketio/socket.io/compare/2.4.0...2.4.1">https://github.com/socketio/socket.io/compare/2.4.0...2.4.1</a></li> <li>Client release: -</li> <li>engine.io version: <code>~3.5.0</code></li> <li>ws version: <code>~7.4.2</code></li> </ul> <h2>2.4.0</h2> <p>Related blog post: <a href="https://socket.io/blog/socket-io-2-4-0/">https://socket.io/blog/socket-io-2-4-0/</a></p> <h3>Features (from Engine.IO)</h3> <ul> <li>add support for all cookie options (<a href="https://github.com/socketio/engine.io/commit/19cc58264a06dca47ed401fbaca32dcdb80a903b">19cc582</a>)</li> <li>disable perMessageDeflate by default (<a href="https://github.com/socketio/engine.io/commit/5ad273601eb66c7b318542f87026837bf9dddd21">5ad2736</a>)</li> </ul> <h3>Bug Fixes</h3> <ul> <li><strong>security:</strong> do not allow all origins by default (<a href="https://github.com/socketio/socket.io/commit/f78a575f66ab693c3ea96ea88429ddb1a44c86c7">f78a575</a>)</li> <li>properly overwrite the query sent in the handshake (<a href="https://github.com/socketio/socket.io/commit/d33a619905a4905c153d4fec337c74da5b533a9e">d33a619</a>)</li> </ul> <p>:warning: <strong>BREAKING CHANGE</strong> :warning:</p> <p>Previously, CORS was enabled by default, which meant that a Socket.IO server sent the necessary CORS headers (<code>Access-Control-Allow-xxx</code>) to <strong>any</strong> domain. This will not be the case anymore, and you now have to explicitly enable it.</p> <!-- raw HTML omitted --> </blockquote> <p>... (truncated)</p> </details> <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/socketio/socket.io/blob/2.4.1/CHANGELOG.md">socket.io's changelog</a>.</em></p> <blockquote> <h2><a href="https://github.com/socketio/socket.io/compare/2.4.0...2.4.1">2.4.1</a> (2021-01-07)</h2> <h3>Reverts</h3> <ul> <li>fix(security): do not allow all origins by default (<a href="https://github.com/socketio/socket.io/commit/a1690509470e9dd5559cec4e60908ca6c23e9ba0">a169050</a>)</li> </ul> <h1><a href="https://github.com/socketio/socket.io/compare/2.3.0...2.4.0">2.4.0</a> (2021-01-04)</h1> <h3>Bug Fixes</h3> <ul> <li><strong>security:</strong> do not allow all origins by default (<a href="https://github.com/socketio/socket.io/commit/f78a575f66ab693c3ea96ea88429ddb1a44c86c7">f78a575</a>)</li> <li>properly overwrite the query sent in the handshake (<a href="https://github.com/socketio/socket.io/commit/d33a619905a4905c153d4fec337c74da5b533a9e">d33a619</a>)</li> </ul> </blockquote> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/socketio/socket.io/commit/e6b869738c73fa0ce9928974d823e50cc92f7a1a"><code>e6b8697</code></a> chore(release): 2.4.1</li> <li><a href="https://github.com/socketio/socket.io/commit/a1690509470e9dd5559cec4e60908ca6c23e9ba0"><code>a169050</code></a> revert: fix(security): do not allow all origins by default</li> <li><a href="https://github.com/socketio/socket.io/commit/873fdc55eddd672960fdbc1325ccb7c4bf466f05"><code>873fdc5</code></a> chore(release): 2.4.0</li> <li><a href="https://github.com/socketio/socket.io/commit/f78a575f66ab693c3ea96ea88429ddb1a44c86c7"><code>f78a575</code></a> fix(security): do not allow all origins by default</li> <li><a href="https://github.com/socketio/socket.io/commit/d33a619905a4905c153d4fec337c74da5b533a9e"><code>d33a619</code></a> fix: properly overwrite the query sent in the handshake</li> <li><a href="https://github.com/socketio/socket.io/commit/3951a79359c19f9497de664d96a8f9f80196a405"><code>3951a79</code></a> chore: bump engine.io version</li> <li><a href="https://github.com/socketio/socket.io/commit/6fa026fc94fb3a1e6674b8a2c1211b24ee38934a"><code>6fa026f</code></a> ci: migrate to GitHub Actions</li> <li>See full diff in <a href="https://github.com/socketio/socket.io/compare/2.3.0...2.4.1">compare view</a></li> </ul> </details> <br />
Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase
.
<details> <summary>Dependabot commands and options</summary> <br />
You can trigger Dependabot actions by commenting on this PR:
@dependabot rebase
will rebase this PR@dependabot recreate
will recreate this PR, overwriting any edits that have been made to it@dependabot merge
will merge this PR after your CI passes on it@dependabot squash and merge
will squash and merge this PR after your CI passes on it@dependabot cancel merge
will cancel a previously requested merge and block automerging@dependabot reopen
will reopen this PR if it is closed@dependabot close
will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually@dependabot ignore this major version
will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this minor version
will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)@dependabot ignore this dependency
will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)@dependabot use these labels
will set the current labels as the default for future PRs for this repo and language@dependabot use these reviewers
will set the current reviewers as the default for future PRs for this repo and language@dependabot use these assignees
will set the current assignees as the default for future PRs for this repo and language@dependabot use this milestone
will set the current milestone as the default for future PRs for this repo and language
You can disable automated security fix PRs for this repo from the Security Alerts page.
</details>
pr created time in a day
create barnchmongodb/js-bson
branch : dependabot/npm_and_yarn/socket.io-2.4.1
created branch time in a day
startedprisma/prisma
started time in a day
startedswift-server/guides
started time in a day
startedfcanas/ogol
started time in a day
startedunsplash/comment-on-pr
started time in a day
startedjohannes/pconn-sapi
started time in 2 days
startedjpsim/ZenTuner
started time in 2 days
issue closedmongodb/js-bson
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
closed time in 2 days
agolin95issue openedmongodb/js-bson
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
created time in 2 days
issue closedmongodb/mongo-swift-driver
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
closed time in 2 days
agolin95issue closedmongodb/mongo-swift-driver
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
closed time in 2 days
agolin95issue closedmongodb/mongo-swift-driver
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
closed time in 2 days
agolin95issue openedmongodb/mongo-swift-driver
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
created time in 2 days