mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-11-04 22:38:43 +00:00
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:
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user