Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 1.1: Improvements & Changes, Some Breaking #8

Merged
merged 11 commits into from
Jul 12, 2022
Merged

Conversation

mergesort
Copy link
Owner

This pull request 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")).

  • Fixing documentation to match all of these changes, please let me know if I missed anything!


I would love to hear all of your feedback about all of these changes, short-term or long-term!

@mergesort
Copy link
Owner Author

@samalone I wanted to check with you about removing .lastAccessed() from ObjectStorage since it was added by you. You had initially added it to DiskStorage so I suspect it's ok, but wanted to check. And I'm curious, do you need it on DiskStorage too, or would lastModified() suffice?

@mergesort mergesort merged commit ee6aa61 into main Jul 12, 2022
@mergesort
Copy link
Owner Author

Merged this in as a precursor to 2.0. 🙂

@mergesort mergesort deleted the 1.1-changes branch July 12, 2022 23:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant