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
parent
1123bccf71
commit
8cb23711ce
|
@ -25,6 +25,7 @@ const {
|
|||
bucket: {
|
||||
bucket_filter,
|
||||
QuoteDataBucket,
|
||||
StagingBucket,
|
||||
},
|
||||
|
||||
dapi: {
|
||||
|
@ -67,7 +68,8 @@ module.exports = Class( 'DocumentServer',
|
|||
),
|
||||
apis
|
||||
),
|
||||
DapiMetaSource( QuoteDataBucket )
|
||||
DapiMetaSource( QuoteDataBucket ),
|
||||
StagingBucket
|
||||
)
|
||||
),
|
||||
} );
|
||||
|
|
|
@ -1140,12 +1140,7 @@ module.exports = Class( 'Server' )
|
|||
parsed_data, request, program, bucket
|
||||
);
|
||||
|
||||
quote.setData( filtered );
|
||||
|
||||
server._monitorMetadataPromise( quote, dapis );
|
||||
|
||||
// calculated values (store only)
|
||||
program.initQuote( bucket, true );
|
||||
}
|
||||
catch ( err )
|
||||
{
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
const { Class } = require( 'easejs' );
|
||||
|
||||
const { QuoteDataBucket } = require( '../../' ).bucket;
|
||||
const { QuoteDataBucket, StagingBucket } = require( '../../' ).bucket;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -56,15 +56,20 @@ module.exports = Class( 'DataProcessor',
|
|||
/**
|
||||
* Initialize processor
|
||||
*
|
||||
* @param {Object} filter bucket filter
|
||||
* @param {function()} dapif data API constructor
|
||||
* @param {DapiMetaSource} meta_source metadata source
|
||||
* The staging bucket constructor will be used to wrap the bucket for
|
||||
* diff-related operations.
|
||||
*
|
||||
* @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._dapif = dapif;
|
||||
this._metaSource = meta_source;
|
||||
this._filter = filter;
|
||||
this._dapif = dapif;
|
||||
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 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
|
||||
const dapis = this._triggerDapis(
|
||||
dapi_manager, program, data, bucket
|
||||
dapi_manager, program, staging.getDiff(), staging
|
||||
);
|
||||
|
||||
staging.commit();
|
||||
|
||||
return {
|
||||
filtered: filtered,
|
||||
dapis: dapis,
|
||||
|
|
|
@ -90,7 +90,7 @@ describe( 'DataProcessor', () =>
|
|||
}
|
||||
};
|
||||
|
||||
Sut( filter, () => {}, meta_source )
|
||||
Sut( filter, () => {}, meta_source, createStubStagingBucket )
|
||||
.processDiff( data, request, program );
|
||||
|
||||
expect( data.filtered ).to.equal( true );
|
||||
|
@ -109,7 +109,7 @@ describe( 'DataProcessor', () =>
|
|||
done();
|
||||
}
|
||||
|
||||
Sut( filter, dapi_factory )
|
||||
Sut( filter, dapi_factory, null, createStubStagingBucket )
|
||||
.processDiff( {}, request, program );
|
||||
} );
|
||||
|
||||
|
@ -136,7 +136,12 @@ describe( 'DataProcessor', () =>
|
|||
meta_source,
|
||||
} = createStubs( false, {}, getFieldData );
|
||||
|
||||
const sut = Sut( filter, () => dapi_manager, meta_source );
|
||||
const sut = Sut(
|
||||
filter,
|
||||
() => dapi_manager,
|
||||
meta_source,
|
||||
createStubStagingBucket
|
||||
);
|
||||
|
||||
program.meta.fields = {
|
||||
foo: {
|
||||
|
@ -249,7 +254,13 @@ function createSutFromStubs( /* see createStubs */ )
|
|||
program: program,
|
||||
filter: filter,
|
||||
meta_source: meta_source,
|
||||
sut: Sut( filter, () => {}, meta_source ),
|
||||
|
||||
sut: Sut(
|
||||
filter,
|
||||
() => {},
|
||||
meta_source,
|
||||
createStubStagingBucket
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -281,6 +292,8 @@ function createStubProgram( internals )
|
|||
internal: internals,
|
||||
meta: { qtypes: {}, fields: {} },
|
||||
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() {},
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue