Inline StoreBytes

This commit is contained in:
Jonathan Lange
2016-07-15 12:58:27 +01:00
parent bbd75ddd24
commit a3648f0c89
2 changed files with 6 additions and 17 deletions

View File

@@ -208,14 +208,9 @@ func (c *MemcacheClient) FetchReports(keys []string) (map[string]report.Report,
func (c *MemcacheClient) StoreReport(key string, report *report.Report) (int, error) {
var buf bytes.Buffer
report.WriteBinary(&buf, c.compressionLevel)
err := c.StoreBytes(key, buf.Bytes())
return buf.Len(), err
}
// StoreBytes stores a report, expecting the report to be serialized already.
func (c *MemcacheClient) StoreBytes(key string, content []byte) error {
return instrument.TimeRequestHistogramStatus("Put", memcacheRequestDuration, memcacheStatusCode, func() error {
item := memcache.Item{Key: key, Value: content, Expiration: c.expiration}
err := instrument.TimeRequestHistogramStatus("Put", memcacheRequestDuration, memcacheStatusCode, func() error {
item := memcache.Item{Key: key, Value: buf.Bytes(), Expiration: c.expiration}
return c.client.Set(&item)
})
return buf.Len(), err
}

View File

@@ -91,19 +91,13 @@ func (store *S3Store) fetchReport(key string) (*report.Report, error) {
func (store *S3Store) StoreReport(key string, report *report.Report) (int, error) {
var buf bytes.Buffer
report.WriteBinary(&buf, gzip.BestCompression)
err := store.StoreBytes(key, buf.Bytes())
return buf.Len(), err
}
// StoreBytes stores a report in S3, expecting the report to be serialized
// already.
func (store *S3Store) StoreBytes(key string, content []byte) error {
return instrument.TimeRequestHistogram("Put", s3RequestDuration, func() error {
err := instrument.TimeRequestHistogram("Put", s3RequestDuration, func() error {
_, err := store.s3.PutObject(&s3.PutObjectInput{
Body: bytes.NewReader(content),
Body: bytes.NewReader(buf.Bytes()),
Bucket: aws.String(store.bucketName),
Key: aws.String(key),
})
return err
})
return buf.Len(), err
}