Skip to content

Releases: mergesort/Bodega

Improvements & Changes, Some Breaking

12 Jul 23:16
ee6aa61
Compare
Choose a tag to compare

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")).

New Functions For All!

29 Jun 02:38
29966bf
Compare
Choose a tag to compare
  • Adding three new functions to DiskStorage and ObjectStorage, createdAt(forKey: CacheKey), lastAccessed(forKey: CacheKey), and lastModified(forKey: CacheKey).

These are useful methods for many use cases such as sorting an array of objects from oldest to newest, by most recently updated, and separately can be useful to derive information for your own purposes such as the last time a certain file was accessed. Thank you to @samalone for coming up with the idea and contributing the majority of the implementation.

  • CacheKey now conforms to Codable and Equatable, allowing it to be used in other Codable and Equatable types.

Let's go shopping! 🛍️

22 Jun 13:11
Compare
Choose a tag to compare
1.0

Adding common directories for cleaner call-sites

CacheKey rules everything around me

18 Jun 01:58
Compare
Choose a tag to compare

CacheKey Changes

  • Adding a CacheKey.init(verbatim:) initializer to make initializing an unsafe cache key explicit.
  • Similar to CacheKey.init(url:), CacheKey.init(_:) now hashes the String that's passed into the initializer.
  • Removing the ability to initialize a CacheKey from a String literal due to a compiler issue.

DiskStorage Changes

  • Removing a non-existent item from disk is now a no-op instead of throwing an error

Getting Real Close…

16 Jun 20:19
Compare
Choose a tag to compare

Coming soon, grab a snack in the mean time. 🍿