@@ -69,49 +69,58 @@ func New(ctx context.Context, config Config) (*Store, error) {
69
69
}
70
70
71
71
func (s * Store ) GetInboxIds (ctx context.Context , req * identity.GetInboxIdsRequest ) (* identity.GetInboxIdsResponse , error ) {
72
- identifiers := []string {}
73
- identifierKinds := []associations.IdentifierKind {}
74
- identifierKindNumbers := []int32 {}
75
- for _ , request := range req .Requests {
76
- identifiers = append (identifiers , request .GetIdentifier ())
72
+ // Create query params with exact capacity needed
73
+ queryParams := queries.GetAddressLogsParams {
74
+ Identifiers : make ([]string , len (req .Requests )),
75
+ IdentifierKinds : make ([]int32 , len (req .Requests )),
76
+ }
77
+
78
+ // Process request data in a single pass
79
+ for i , request := range req .Requests {
80
+ queryParams .Identifiers [i ] = request .GetIdentifier ()
77
81
82
+ // Coalesce unspecified to ethereum
78
83
identifierKind := request .GetIdentifierKind ()
79
- // Old libXmtp versions will come in as unspecified. We need to coalesce them to ethereum.
80
84
if identifierKind == associations .IdentifierKind_IDENTIFIER_KIND_UNSPECIFIED {
81
85
identifierKind = associations .IdentifierKind_IDENTIFIER_KIND_ETHEREUM
82
86
}
83
- identifierKinds = append (identifierKinds , identifierKind )
84
- identifierKindNumbers = append (identifierKindNumbers , int32 (identifierKind .Number ()))
87
+ queryParams .IdentifierKinds [i ] = int32 (identifierKind .Number ())
85
88
}
86
89
87
- addressLogEntries , err := s .queries .GetAddressLogs (ctx , queries.GetAddressLogsParams {
88
- Identifiers : identifiers ,
89
- IdentifierKinds : identifierKindNumbers ,
90
- })
90
+ // Query the database
91
+ addressLogEntries , err := s .queries .GetAddressLogs (ctx , queryParams )
91
92
if err != nil {
92
93
return nil , err
93
94
}
94
95
95
- out := make ([]* identity.GetInboxIdsResponse_Response , len (identifiers ))
96
+ // Build responses with the same capacity as requests
97
+ responses := make ([]* identity.GetInboxIdsResponse_Response , len (req .Requests ))
96
98
97
- for index , identifier := range identifiers {
98
- resp := identity. GetInboxIdsResponse_Response {}
99
- resp . Identifier = identifier
100
- identifierKind := identifierKinds [ index ]
101
- resp . IdentifierKind = identifierKind
102
- identifierKindNumber := int32 ( identifierKind . Number ())
99
+ for i , request := range req . Requests {
100
+ identifier := request . GetIdentifier ()
101
+ identifierKind := request . GetIdentifierKind ()
102
+ if identifierKind == associations . IdentifierKind_IDENTIFIER_KIND_UNSPECIFIED {
103
+ identifierKind = associations . IdentifierKind_IDENTIFIER_KIND_ETHEREUM
104
+ }
103
105
106
+ // Create response with the required identifier information
107
+ responses [i ] = & identity.GetInboxIdsResponse_Response {
108
+ Identifier : identifier ,
109
+ IdentifierKind : identifierKind ,
110
+ }
111
+
112
+ // Find matching inbox ID directly from addressLogEntries
113
+ identifierKindNumber := int32 (identifierKind .Number ())
104
114
for _ , logEntry := range addressLogEntries {
105
115
if logEntry .Identifier == identifier && logEntry .IdentifierKind == identifierKindNumber {
106
- resp .InboxId = & logEntry .InboxID
116
+ responses [ i ] .InboxId = & logEntry .InboxID
107
117
break
108
118
}
109
119
}
110
- out [index ] = & resp
111
120
}
112
121
113
122
return & identity.GetInboxIdsResponse {
114
- Responses : out ,
123
+ Responses : responses ,
115
124
}, nil
116
125
}
117
126
0 commit comments