I shared a pretty crappy (in hindsight) method of data change detection some time ago.
A few days after I decided to use hashes instead. I’ve tried many ways to efficiently detect multiple fields for changes in one data trigger and hashes is the way to go. It’s nothing new in DB management but will be quite new to most Bubblers.
How to:
It’s actually pretty easy to pull off because Bubble already has hashing as a native operator.
- Just create a new field to store the hash.
- Whenever data gets changed, just create the hash and store it.
- In the data trigger just compare the hashes of
beforeandnow
What should be in a hash?
Whatever values that you want to detect changes in:
Just create a combined string of field values
For example:
field1-field2-field3-UserID
IMPORTANT: Hashes are affected by the sequence of characters so
field1-field2-field3-UserID is not the same as field3-field2-field1-UserID even if the field values are the same.
Other Benefits
- Hashes will always be a fixed sized regardless of the original string (eg. MD5 always produces a 16 byte string even if the original string is 1MB)
- You can create different hashes to detect different groups of changes
- Employ Merkle Trees: Hash a group of hashes from rows of data to detect any changes within large rows of data. (eg. store group hashes as a separate data type and run periodical checks; great for ensuring syncing with an external database)
- Heck go crazy and hash the hashed hash groups for very large checks.
Conclusion
The reason I like this method is because it doesn’t use any plugins. Hashing is just another Bubble operator.
