Rebuild BR Issue_5048

Moves calls to compress/decompress the text/textBin document members to the hombrewery model code. Compression is done in a save().pre setup. Decompression was already handled in the static for loading a brew but the textBin member was not emptied on decompression.
This commit is contained in:
David Bolack
2026-10-13 12:16:26 -05:00
parent 3179c56263
commit c5461f2ea2
4 changed files with 88 additions and 97 deletions
+8
View File
@@ -32,6 +32,13 @@ const HomebrewSchema = mongoose.Schema({
lock : { type: Object, index: true }
}, { versionKey: false });
HomebrewSchema.pre('save', ()=>{
if(!this.googleId) {
this.textBin = zlib.deflateRawSync(this.text);
this.text = undefined;
}
});
HomebrewSchema.statics.increaseView = async function(query) {
const brew = await Homebrew.findOne(query).exec();
brew.lastViewed = new Date();
@@ -51,6 +58,7 @@ HomebrewSchema.statics.get = async function(query, fields=null){
if(!_.isNil(brew.textBin)) { // Uncompress zipped text field
const unzipped = zlib.inflateRawSync(brew.textBin);
brew.text = unzipped.toString();
brew.textBin = undefined;
}
return brew;
};