Skip to content

Commit 3f8d9b3

Browse files
committed
Add comment explaining the passing of tempRecordsHolder and improve New()'s comment
1 parent 4720bd2 commit 3f8d9b3

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

client.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type Client struct {
3030
HTTPClient *http.Client
3131
}
3232

33-
// New creates a new instance of the Airtable client or returns an error if one is encountered.
33+
// New creates a new instance of the Airtable client
3434
func New(apiKey, baseID string) (*Client, error) {
3535
if !utils.IsValidAPIKey(apiKey) {
3636
return nil, fmt.Errorf("invalid API Key encountered: %s", apiKey)
@@ -65,6 +65,10 @@ func (c *Client) ListRecords(tableName string, recordsHolder interface{}, listPa
6565
}
6666
tempRecordsHolder := reflect.New(reflect.TypeOf(recordsHolder).Elem()).Interface()
6767
offsetHash := ""
68+
// We pass tempRecordsHolder here as a perf optimization so that we do not need to re-derive
69+
// the tempRecord for each request using reflection, but can instead reuse a single one. Since
70+
// tempRecordsHolder is always a slice, it's contents will be entirely replaced with each
71+
// subsequent unmarshalling.
6872
return c.recursivelyListRecordsAtOffset(endpoint, offsetHash, tempRecordsHolder, recordsHolder)
6973
}
7074

0 commit comments

Comments
 (0)