@@ -798,10 +798,10 @@ export class Provider implements StorageProvider {
798798 return entity ?. is as StorageValue < T > | undefined ;
799799 }
800800 async send < T = any > (
801- changes : { entityId : EntityId ; value : StorageValue < T > } [ ] ,
801+ batch : { entityId : EntityId ; value : StorageValue < T > } [ ] ,
802802 ) : Promise <
803803 Result <
804- Commit ,
804+ Unit ,
805805 | ConflictError
806806 | TransactionError
807807 | ConnectionError
@@ -810,17 +810,31 @@ export class Provider implements StorageProvider {
810810 | StoreError
811811 >
812812 > {
813- const { the } = this ;
814-
815- const result = await this . workspace . push ( changes . map ( ( change ) => ( {
816- the,
817- of : Provider . toEntity ( change . entityId ) ,
818- // ⚠️ We do JSON roundtrips to strip of the undefined values that
819- // cause problems with serialization.
820- is : JSON . parse ( JSON . stringify ( change . value ) ) ,
821- } ) ) ) ;
813+ const { the, workspace } = this ;
814+
815+ const changes = [ ] ;
816+ for ( const { entityId, value } of batch ) {
817+ const of = Provider . toEntity ( entityId ) ;
818+ const content = JSON . stringify ( value ) ;
819+
820+ const current = workspace . get ( { the, of } ) ;
821+ if ( JSON . stringify ( current ) !== content ) {
822+ changes . push ( {
823+ the,
824+ of,
825+ // ⚠️ We do JSON roundtrips to strip of the undefined values that
826+ // cause problems with serialization.
827+ is : JSON . parse ( content ) as JSONValue ,
828+ } ) ;
829+ }
830+ }
822831
823- return result ;
832+ if ( changes . length > 0 ) {
833+ const result = await this . workspace . push ( changes ) ;
834+ return result . error ? result : { ok : { } } ;
835+ } else {
836+ return { ok : { } } ;
837+ }
824838 }
825839
826840 parse ( source : string ) : Memory . ProviderCommand < Memory . Protocol > {
0 commit comments