1
0
Fork 0

server: Auto-populate liza_timestamp_initial_rated in metabucket

This value already existed on the document, but was inaccessible to external
systems.  This is now accessible to e.g. raters.

* doc/bucket.texi (Metabucket): New section.
* src/server/db/MongoServerDao.js (saveQuote): Set initial quoted date as
    liza_timestamp_initial_rated.  Update metabucket keys individually so as
    not to inadvertently overwrite the entire metabucket.

DEV-3715
master
Mike Gerwitz 2019-02-05 15:59:40 -05:00
parent 37a6805110
commit 833017c359
2 changed files with 41 additions and 2 deletions

View File

@ -16,6 +16,7 @@
* Value Assignment:Bucket Assignment. Writing data to the Bucket.
* Bucket Diff:: Representing bucket changes.
* Calculated Values:: Dynamic data derived from other values.
* Metabucket:: Bucket holding document metadata
@end menu
@ -116,3 +117,32 @@ A diff is applied to the underlying bucket by invoking
@node Calculated Values
@section Calculated Values
@helpwanted
@node Metabucket
@section Metabucket
@cindex Metabucket
The @dfn{metabucket} is a loosely-structured key/value store
separate from the data bucket.@footnote{
It is stored in the @code{meta} field on the Mongo document.}
It should be used to save data that should be accessible only to the server,
but never the client.
The client has no means by which to access the metabucket.
Custom fields can be populated by server-side DataAPIs
(@pxref{Server-Side Data API Calls}).
Any fields prefixed with the string @samp{liza_} are reserved and are
populated automatically by the Server.
They are shown in @ref{t:liza-meta}.
@float Table, t:liza-meta
@table @code
@cindex Initial rated date
@item liza_timestamp_initial_rated
A Unix timestamp representing the first time a document was acted
upon by a rating service.
This value is set once and is never updated or cleared.
@end table
@caption{Metabucket fields populated automatically by the Server}
@end float

View File

@ -287,7 +287,8 @@ module.exports = Class( 'MongoServerDao' )
quote, success_callback, failure_callback, save_data
)
{
var dao = this;
var dao = this;
const meta = {};
// if we're not ready, then we can't save the quote!
if ( this._ready === false )
@ -309,7 +310,7 @@ module.exports = Class( 'MongoServerDao' )
};
// full save will include all metadata
save_data.meta = quote.getMetabucket().getData();
meta = quote.getMetabucket().getData();
}
// when we update the quote data, clear quick save data (this data
@ -333,9 +334,17 @@ module.exports = Class( 'MongoServerDao' )
( new Date() ).getTime() / 1000
);
// meta will eventually take over for much of the above data
meta.liza_timestamp_initial_rated = quote.getRatedDate();
// save the stack so we can track this call via the oplog
save_data._stack = ( new Error() ).stack;
// avoid wiping out other metadata (since this may not be a full set)
Object.keys( meta ).forEach(
key => save_data[ 'meta.' + key ] = meta[ key ]
);
// update the quote data if it already exists (same id), otherwise
// insert it
this._collection.update( { id: id },