@@ -16,6 +16,18 @@ var debug = require('debug')('loopback:persisted-model');
16
16
var PassThrough = require ( 'stream' ) . PassThrough ;
17
17
var utils = require ( './utils' ) ;
18
18
19
+ // workaround for low performance of strong-globalize
20
+ // see https://github.com/strongloop/strong-globalize/issues/66
21
+ var stringCache = Object . create ( null ) ;
22
+ g . s = function ( str ) {
23
+ assert . equal ( 1 , arguments . length , 'g.s() does not support parameters' ) ;
24
+ if ( str in stringCache )
25
+ return stringCache [ str ] ;
26
+ var result = g . t ( str ) ;
27
+ stringCache [ str ] = result ;
28
+ return result ;
29
+ } ;
30
+
19
31
module . exports = function ( registry ) {
20
32
var Model = registry . getModel ( 'Model' ) ;
21
33
@@ -560,7 +572,7 @@ module.exports = function(registry) {
560
572
}
561
573
562
574
setRemoting ( PersistedModel , 'create' , {
563
- description : g . f ( 'Create a new instance of the model and persist it into the data source.' ) ,
575
+ description : g . s ( 'Create a new instance of the model and persist it into the data source.' ) ,
564
576
accessType : 'WRITE' ,
565
577
accepts : { arg : 'data' , type : 'object' , description : 'Model instance data' , http : { source : 'body' } } ,
566
578
returns : { arg : 'data' , type : typeName , root : true } ,
@@ -569,7 +581,7 @@ module.exports = function(registry) {
569
581
570
582
setRemoting ( PersistedModel , 'upsert' , {
571
583
aliases : [ 'updateOrCreate' ] ,
572
- description : g . f ( 'Update an existing model instance or insert a new one ' +
584
+ description : g . s ( 'Update an existing model instance or insert a new one ' +
573
585
'into the data source.' ) ,
574
586
accessType : 'WRITE' ,
575
587
accepts : { arg : 'data' , type : 'object' , description : 'Model instance data' , http : { source : 'body' } } ,
@@ -578,7 +590,7 @@ module.exports = function(registry) {
578
590
} ) ;
579
591
580
592
setRemoting ( PersistedModel , 'exists' , {
581
- description : g . f ( 'Check whether a model instance exists in the data source.' ) ,
593
+ description : g . s ( 'Check whether a model instance exists in the data source.' ) ,
582
594
accessType : 'READ' ,
583
595
accepts : { arg : 'id' , type : 'any' , description : 'Model id' , required : true } ,
584
596
returns : { arg : 'exists' , type : 'boolean' } ,
@@ -609,29 +621,29 @@ module.exports = function(registry) {
609
621
} ) ;
610
622
611
623
setRemoting ( PersistedModel , 'findById' , {
612
- description : g . f ( 'Find a model instance by {{id}} from the data source.' ) ,
624
+ description : g . s ( 'Find a model instance by {{id}} from the data source.' ) ,
613
625
accessType : 'READ' ,
614
626
accepts : [
615
627
{ arg : 'id' , type : 'any' , description : 'Model id' , required : true ,
616
628
http : { source : 'path' } } ,
617
629
{ arg : 'filter' , type : 'object' ,
618
- description : g . f ( 'Filter defining fields and include' ) } ,
630
+ description : g . s ( 'Filter defining fields and include' ) } ,
619
631
] ,
620
632
returns : { arg : 'data' , type : typeName , root : true } ,
621
633
http : { verb : 'get' , path : '/:id' } ,
622
634
rest : { after : convertNullToNotFoundError }
623
635
} ) ;
624
636
625
637
setRemoting ( PersistedModel , 'find' , {
626
- description : g . f ( 'Find all instances of the model matched by filter from the data source.' ) ,
638
+ description : g . s ( 'Find all instances of the model matched by filter from the data source.' ) ,
627
639
accessType : 'READ' ,
628
640
accepts : { arg : 'filter' , type : 'object' , description : 'Filter defining fields, where, include, order, offset, and limit' } ,
629
641
returns : { arg : 'data' , type : [ typeName ] , root : true } ,
630
642
http : { verb : 'get' , path : '/' }
631
643
} ) ;
632
644
633
645
setRemoting ( PersistedModel , 'findOne' , {
634
- description : g . f ( 'Find first instance of the model matched by filter from the data source.' ) ,
646
+ description : g . s ( 'Find first instance of the model matched by filter from the data source.' ) ,
635
647
accessType : 'READ' ,
636
648
accepts : { arg : 'filter' , type : 'object' , description : 'Filter defining fields, where, include, order, offset, and limit' } ,
637
649
returns : { arg : 'data' , type : typeName , root : true } ,
@@ -640,7 +652,7 @@ module.exports = function(registry) {
640
652
} ) ;
641
653
642
654
setRemoting ( PersistedModel , 'destroyAll' , {
643
- description : g . f ( 'Delete all matching records.' ) ,
655
+ description : g . s ( 'Delete all matching records.' ) ,
644
656
accessType : 'WRITE' ,
645
657
accepts : { arg : 'where' , type : 'object' , description : 'filter.where object' } ,
646
658
returns : {
@@ -655,17 +667,17 @@ module.exports = function(registry) {
655
667
656
668
setRemoting ( PersistedModel , 'updateAll' , {
657
669
aliases : [ 'update' ] ,
658
- description : g . f ( 'Update instances of the model matched by {{where}} from the data source.' ) ,
670
+ description : g . s ( 'Update instances of the model matched by {{where}} from the data source.' ) ,
659
671
accessType : 'WRITE' ,
660
672
accepts : [
661
673
{ arg : 'where' , type : 'object' , http : { source : 'query' } ,
662
- description : g . f ( 'Criteria to match model instances' ) } ,
674
+ description : g . s ( 'Criteria to match model instances' ) } ,
663
675
{ arg : 'data' , type : 'object' , http : { source : 'body' } ,
664
- description : g . f ( 'An object of model property name/value pairs' ) } ,
676
+ description : g . s ( 'An object of model property name/value pairs' ) } ,
665
677
] ,
666
678
returns : {
667
679
arg : 'count' ,
668
- description : g . f ( 'The number of instances updated' ) ,
680
+ description : g . s ( 'The number of instances updated' ) ,
669
681
type : 'object' ,
670
682
root : true
671
683
} ,
@@ -674,7 +686,7 @@ module.exports = function(registry) {
674
686
675
687
setRemoting ( PersistedModel , 'deleteById' , {
676
688
aliases : [ 'destroyById' , 'removeById' ] ,
677
- description : g . f ( 'Delete a model instance by {{id}} from the data source.' ) ,
689
+ description : g . s ( 'Delete a model instance by {{id}} from the data source.' ) ,
678
690
accessType : 'WRITE' ,
679
691
accepts : { arg : 'id' , type : 'any' , description : 'Model id' , required : true ,
680
692
http : { source : 'path' } } ,
@@ -683,15 +695,15 @@ module.exports = function(registry) {
683
695
} ) ;
684
696
685
697
setRemoting ( PersistedModel , 'count' , {
686
- description : g . f ( 'Count instances of the model matched by where from the data source.' ) ,
698
+ description : g . s ( 'Count instances of the model matched by where from the data source.' ) ,
687
699
accessType : 'READ' ,
688
700
accepts : { arg : 'where' , type : 'object' , description : 'Criteria to match model instances' } ,
689
701
returns : { arg : 'count' , type : 'number' } ,
690
702
http : { verb : 'get' , path : '/count' }
691
703
} ) ;
692
704
693
705
setRemoting ( PersistedModel . prototype , 'updateAttributes' , {
694
- description : g . f ( 'Update attributes for a model instance and persist it into ' +
706
+ description : g . s ( 'Update attributes for a model instance and persist it into ' +
695
707
'the data source.' ) ,
696
708
accessType : 'WRITE' ,
697
709
accepts : { arg : 'data' , type : 'object' , http : { source : 'body' } , description : 'An object of model property name/value pairs' } ,
@@ -701,7 +713,7 @@ module.exports = function(registry) {
701
713
702
714
if ( options . trackChanges || options . enableRemoteReplication ) {
703
715
setRemoting ( PersistedModel , 'diff' , {
704
- description : g . f ( 'Get a set of deltas and conflicts since the given checkpoint.' ) ,
716
+ description : g . s ( 'Get a set of deltas and conflicts since the given checkpoint.' ) ,
705
717
accessType : 'READ' ,
706
718
accepts : [
707
719
{ arg : 'since' , type : 'number' , description : 'Find deltas since this checkpoint' } ,
@@ -713,7 +725,7 @@ module.exports = function(registry) {
713
725
} ) ;
714
726
715
727
setRemoting ( PersistedModel , 'changes' , {
716
- description : g . f ( 'Get the changes to a model since a given checkpoint.' +
728
+ description : g . s ( 'Get the changes to a model since a given checkpoint.' +
717
729
'Provide a filter object to reduce the number of results returned.' ) ,
718
730
accessType : 'READ' ,
719
731
accepts : [
@@ -725,7 +737,7 @@ module.exports = function(registry) {
725
737
} ) ;
726
738
727
739
setRemoting ( PersistedModel , 'checkpoint' , {
728
- description : g . f ( 'Create a checkpoint.' ) ,
740
+ description : g . s ( 'Create a checkpoint.' ) ,
729
741
// The replication algorithm needs to create a source checkpoint,
730
742
// even though it is otherwise not making any source changes.
731
743
// We need to allow this method for users that don't have full
@@ -736,14 +748,14 @@ module.exports = function(registry) {
736
748
} ) ;
737
749
738
750
setRemoting ( PersistedModel , 'currentCheckpoint' , {
739
- description : g . f ( 'Get the current checkpoint.' ) ,
751
+ description : g . s ( 'Get the current checkpoint.' ) ,
740
752
accessType : 'READ' ,
741
753
returns : { arg : 'checkpoint' , type : 'object' , root : true } ,
742
754
http : { verb : 'get' , path : '/checkpoint' }
743
755
} ) ;
744
756
745
757
setRemoting ( PersistedModel , 'createUpdates' , {
746
- description : g . f ( 'Create an update list from a delta list.' ) ,
758
+ description : g . s ( 'Create an update list from a delta list.' ) ,
747
759
// This operation is read-only, it does not change any local data.
748
760
// It is called by the replication algorithm to compile a list
749
761
// of changes to apply on the target.
@@ -754,14 +766,14 @@ module.exports = function(registry) {
754
766
} ) ;
755
767
756
768
setRemoting ( PersistedModel , 'bulkUpdate' , {
757
- description : g . f ( 'Run multiple updates at once. Note: this is not atomic.' ) ,
769
+ description : g . s ( 'Run multiple updates at once. Note: this is not atomic.' ) ,
758
770
accessType : 'WRITE' ,
759
771
accepts : { arg : 'updates' , type : 'array' } ,
760
772
http : { verb : 'post' , path : '/bulk-update' }
761
773
} ) ;
762
774
763
775
setRemoting ( PersistedModel , 'findLastChange' , {
764
- description : g . f ( 'Get the most recent change record for this instance.' ) ,
776
+ description : g . s ( 'Get the most recent change record for this instance.' ) ,
765
777
accessType : 'READ' ,
766
778
accepts : {
767
779
arg : 'id' , type : 'any' , required : true , http : { source : 'path' } ,
@@ -773,7 +785,7 @@ module.exports = function(registry) {
773
785
774
786
setRemoting ( PersistedModel , 'updateLastChange' , {
775
787
description : [
776
- g . f ( 'Update the properties of the most recent change record ' +
788
+ g . s ( 'Update the properties of the most recent change record ' +
777
789
'kept for this instance.' ) ,
778
790
] ,
779
791
accessType : 'WRITE' ,
@@ -784,7 +796,7 @@ module.exports = function(registry) {
784
796
} ,
785
797
{
786
798
arg : 'data' , type : 'object' , http : { source : 'body' } ,
787
- description : g . f ( 'An object of Change property name/value pairs' ) ,
799
+ description : g . s ( 'An object of Change property name/value pairs' ) ,
788
800
} ,
789
801
] ,
790
802
returns : { arg : 'result' , type : this . Change . modelName , root : true } ,
@@ -810,7 +822,7 @@ module.exports = function(registry) {
810
822
}
811
823
812
824
setRemoting ( PersistedModel , 'createChangeStream' , {
813
- description : g . f ( 'Create a change stream.' ) ,
825
+ description : g . s ( 'Create a change stream.' ) ,
814
826
accessType : 'READ' ,
815
827
http : [
816
828
{ verb : 'post' , path : '/change-stream' } ,
0 commit comments