Skip to content

Improvements & Changes, Some Breaking

Compare
Choose a tag to compare
@mergesort mergesort released this 12 Jul 23:16
· 92 commits to main since this release
ee6aa61

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 new ObjectStorage or DiskStorage pointing to a subdirectory to replicate the functionality the subdirectory 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() from ObjectStorage. When ObjectStorage was guaranteed to have a DiskStorage under the hood we could call the underlying DiskStorage's version of this method to figure out when the object was last accessed. But going forward ObjectStorage is no longer guaranteed to use DiskStorage, for example as we use will use DatabaseStorage in the future. The method will still remain available on DiskStorage, with no changes to lastModified() or creationDate().

  • 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 in DiskStorage+Directories. The initializer for ObjectStorage or DiskStorage now looks like init(directory: Directory) rather than init(storagePath: URL), which allows for shorter, type-safe, and file-system safe initializers such as DiskStorage(directory: .documents(appendingPath: "Notes")).