1
0
Fork 0

Recognize non-changes in posted data server-side

This is a terrible kluge, but time doesn't permit modifying the
system.  All of this also touches old code that is untested, which is
difficult to modify with confidence.

* src/server/DocumentServer.js (DocumentServer#create): Use
  StagingBucket.
* src/server/Server.js: Remove logic now handled by DataProcessor.
* src/server/request/DataProcessor.js (processDiff): Wrap in
  StagingBucket to filter out values that do not result in changes.
* test/server/request/DataProcessorTest.js: Update failing cases.
master
Mike Gerwitz 2017-08-11 13:39:08 -04:00
parent 1123bccf71
commit 8cb23711ce
4 changed files with 68 additions and 19 deletions

View File

@ -25,6 +25,7 @@ const {
bucket: { bucket: {
bucket_filter, bucket_filter,
QuoteDataBucket, QuoteDataBucket,
StagingBucket,
}, },
dapi: { dapi: {
@ -67,7 +68,8 @@ module.exports = Class( 'DocumentServer',
), ),
apis apis
), ),
DapiMetaSource( QuoteDataBucket ) DapiMetaSource( QuoteDataBucket ),
StagingBucket
) )
), ),
} ); } );

View File

@ -1140,12 +1140,7 @@ module.exports = Class( 'Server' )
parsed_data, request, program, bucket parsed_data, request, program, bucket
); );
quote.setData( filtered );
server._monitorMetadataPromise( quote, dapis ); server._monitorMetadataPromise( quote, dapis );
// calculated values (store only)
program.initQuote( bucket, true );
} }
catch ( err ) catch ( err )
{ {

View File

@ -23,7 +23,7 @@
const { Class } = require( 'easejs' ); const { Class } = require( 'easejs' );
const { QuoteDataBucket } = require( '../../' ).bucket; const { QuoteDataBucket, StagingBucket } = require( '../../' ).bucket;
/** /**
@ -56,15 +56,20 @@ module.exports = Class( 'DataProcessor',
/** /**
* Initialize processor * Initialize processor
* *
* @param {Object} filter bucket filter * The staging bucket constructor will be used to wrap the bucket for
* @param {function()} dapif data API constructor * diff-related operations.
* @param {DapiMetaSource} meta_source metadata source *
* @param {Object} filter bucket filter
* @param {function()} dapif data API constructor
* @param {DapiMetaSource} meta_source metadata source
* @param {function(Bucket)} staging_ctor staging bucket constructor
*/ */
constructor( filter, dapif, meta_source ) constructor( filter, dapif, meta_source, staging_ctor )
{ {
this._filter = filter; this._filter = filter;
this._dapif = dapif; this._dapif = dapif;
this._metaSource = meta_source; this._metaSource = meta_source;
this._stagingCtor = staging_ctor;
}, },
@ -86,12 +91,21 @@ module.exports = Class( 'DataProcessor',
{ {
const filtered = this.sanitizeDiff( data, request, program, false ); const filtered = this.sanitizeDiff( data, request, program, false );
const dapi_manager = this._dapif( program.apis, request ); const dapi_manager = this._dapif( program.apis, request );
const staging = this._stagingCtor( bucket );
// forbidBypass will force diff generation on initQuote
staging.setValues( filtered, true );
staging.forbidBypass();
program.initQuote( staging, true );
// array of promises for any dapi requests // array of promises for any dapi requests
const dapis = this._triggerDapis( const dapis = this._triggerDapis(
dapi_manager, program, data, bucket dapi_manager, program, staging.getDiff(), staging
); );
staging.commit();
return { return {
filtered: filtered, filtered: filtered,
dapis: dapis, dapis: dapis,

View File

@ -90,7 +90,7 @@ describe( 'DataProcessor', () =>
} }
}; };
Sut( filter, () => {}, meta_source ) Sut( filter, () => {}, meta_source, createStubStagingBucket )
.processDiff( data, request, program ); .processDiff( data, request, program );
expect( data.filtered ).to.equal( true ); expect( data.filtered ).to.equal( true );
@ -109,7 +109,7 @@ describe( 'DataProcessor', () =>
done(); done();
} }
Sut( filter, dapi_factory ) Sut( filter, dapi_factory, null, createStubStagingBucket )
.processDiff( {}, request, program ); .processDiff( {}, request, program );
} ); } );
@ -136,7 +136,12 @@ describe( 'DataProcessor', () =>
meta_source, meta_source,
} = createStubs( false, {}, getFieldData ); } = createStubs( false, {}, getFieldData );
const sut = Sut( filter, () => dapi_manager, meta_source ); const sut = Sut(
filter,
() => dapi_manager,
meta_source,
createStubStagingBucket
);
program.meta.fields = { program.meta.fields = {
foo: { foo: {
@ -249,7 +254,13 @@ function createSutFromStubs( /* see createStubs */ )
program: program, program: program,
filter: filter, filter: filter,
meta_source: meta_source, meta_source: meta_source,
sut: Sut( filter, () => {}, meta_source ),
sut: Sut(
filter,
() => {},
meta_source,
createStubStagingBucket
),
}; };
} }
@ -281,6 +292,8 @@ function createStubProgram( internals )
internal: internals, internal: internals,
meta: { qtypes: {}, fields: {} }, meta: { qtypes: {}, fields: {} },
apis: {}, apis: {},
initQuote() {},
}; };
} }
@ -305,3 +318,28 @@ function createStubBucket( data )
}, },
}; };
} }
function createStubStagingBucket( bucket )
{
let data = {};
return {
getDataByName( name )
{
return bucket.getDataByName( name );
},
setValues( values )
{
data = values;
},
forbidBypass() {},
getDiff()
{
return data;
},
commit() {},
};
}