Improvements & Changes, Some Breaking
This release has many changes, and some of them are breaking. This is work that's important for Bodega (and Boutique), improving upon and fixing some assumptions I'd made earlier in the development lifecycle of Bodega, before there even was a Boutique.
Aside from improvements this version will lay the foundation for a version 2.0 of Bodega and Boutique, one that will offer some very significant and much-needed performance improvements. Having gone through the exercise of optimizing most anything that can provide a reasonable boost in performance, now 85% of the time Bodega spends on reading or writing is filesystem-based operations, many of which are ones I can't tune. To remedy this Bodega 2.0 will offer a database-powered variant of the underlying Storage (currently DiskStorage
), while leaving ObjectStorage
unchanged. This will mean that your code doesn't have to change, but may require data that you can't repopulate to be manually migrated.
You will have the ability to stay on 1.x versions of the library if you don't want to make any changes, but Bodega 2.0 will provide a new DatabaseStorage
option that uses SQLite under the hood and provides 400% faster performance. This is especially useful for apps that have large data sets (10,000+ objects), as many production apps do, and will be the default storage option for Boutique 2.0.
Now that we know why these changes are being made, here are the changes in this pull request.
- Removing the concept of subdirectories, and all of
subdirectory
parameters. The subdirectory is complicated, error-prone, and in practice doesn't have much use. When I first started working on Bodega I was using subdirectories to shard objects, but now you can easily create a newObjectStorage
orDiskStorage
pointing to a subdirectory to replicate the functionality thesubdirectory
parameter offers. The benefit is a much simpler and clearer API, and removes much surface area for bugs such as this code.
let keys = store.allKeys(inSubdirectory: "subdirectory")
let objects = store.objects(forKeys: keys, inSubdirectory: "subdirectory")
// Returns 0 objects because you're actually querying folder/subdirectory/subdirectory, not folder/subdirectory as you may expect.
-
Removing
.lastAccessed()
fromObjectStorage
. WhenObjectStorage
was guaranteed to have aDiskStorage
under the hood we could call the underlyingDiskStorage
's version of this method to figure out when the object was last accessed. But going forwardObjectStorage
is no longer guaranteed to useDiskStorage
, for example as we use will useDatabaseStorage
in the future. The method will still remain available onDiskStorage
, with no changes tolastModified()
orcreationDate()
. -
Adding
applicationSupportDirectory()
on the Mac. If you have suggestions for other useful directories please let me know. -
Adding a new type,
FileManager.Directory
, to provide a type-safe replacement for the folders inDiskStorage+Directories
. The initializer forObjectStorage
orDiskStorage
now looks likeinit(directory: Directory)
rather thaninit(storagePath: URL)
, which allows for shorter, type-safe, and file-system safe initializers such asDiskStorage(directory: .documents(appendingPath: "Notes"))
.