Skip to content

Commit

Permalink
fix(cache): Fixed caching for institutions.
Browse files Browse the repository at this point in the history
I made a wrapper around the status so that it should properly marshall
with msgpack.
  • Loading branch information
elliotcourant committed Aug 14, 2023
1 parent ceee6e4 commit e9ecb6b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
8 changes: 4 additions & 4 deletions pkg/cache/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package cache

import (
"context"
"encoding/json"
"fmt"
"time"

"github.com/getsentry/sentry-go"
"github.com/gomodule/redigo/redis"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/vmihailenco/msgpack/v5"
)

type Cache interface {
Expand Down Expand Up @@ -107,7 +107,7 @@ func (r *redisCache) SetEz(ctx context.Context, key string, object interface{})
defer span.Finish()
span.Description = ""

data, err := json.Marshal(object)
data, err := msgpack.Marshal(object)
if err != nil {
return errors.Wrap(err, "failed to marshal item to be cached")
}
Expand All @@ -120,7 +120,7 @@ func (r *redisCache) SetEzTTL(ctx context.Context, key string, object interface{
defer span.Finish()
span.Description = "Redis - SetEzTTL"

data, err := json.Marshal(object)
data, err := msgpack.Marshal(object)
if err != nil {
return errors.Wrap(err, "failed to marshal item to be cached")
}
Expand Down Expand Up @@ -180,7 +180,7 @@ func (r *redisCache) GetEz(ctx context.Context, key string, output interface{})
return nil
}

if err = json.Unmarshal(data, output); err != nil {
if err = msgpack.Unmarshal(data, output); err != nil {
span.Status = sentry.SpanStatusDataLoss
return errors.Wrap(err, "failed to unmarshal from cache")
}
Expand Down
38 changes: 29 additions & 9 deletions pkg/platypus/institutions.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,25 @@ var (
)

type PlaidInstitution struct {
InstitutionId string `json:"institutionId"`
Name string `json:"name"`
Products []plaid.Products `json:"products"`
CountryCodes []plaid.CountryCode `json:"countryCodes"`
URL string `json:"url,omitempty"`
PrimaryColor string `json:"primaryColor,omitempty"`
Logo string `json:"logo,omitempty"`
Status plaid.InstitutionStatus `json:"status"`
InstitutionId string `json:"institutionId"`
Name string `json:"name"`
Products []plaid.Products `json:"products"`
CountryCodes []plaid.CountryCode `json:"countryCodes"`
URL string `json:"url,omitempty"`
PrimaryColor string `json:"primaryColor,omitempty"`
Logo string `json:"logo,omitempty"`
Status Status `json:"status"`
}

type Status struct {
ItemLogins plaid.ProductStatus `json:"item_logins,omitempty"`
TransactionsUpdates plaid.ProductStatus `json:"transactions_updates,omitempty"`
Auth plaid.ProductStatus `json:"auth,omitempty"`
Identity plaid.ProductStatus `json:"identity,omitempty"`
InvestmentsUpdates plaid.ProductStatus `json:"investments_updates,omitempty"`
LiabilitiesUpdates plaid.ProductStatus `json:"liabilities_updates,omitempty"`
Liabilities plaid.ProductStatus `json:"liabilities,omitempty"`
Investments plaid.ProductStatus `json:"investments,omitempty"`
}

func NewPlaidInstitution(input plaid.Institution) PlaidInstitution {
Expand All @@ -39,7 +50,16 @@ func NewPlaidInstitution(input plaid.Institution) PlaidInstitution {
URL: input.GetUrl(),
PrimaryColor: input.GetPrimaryColor(),
Logo: input.GetLogo(),
Status: input.GetStatus(),
Status: Status{
ItemLogins: input.Status.Get().GetItemLogins(),
TransactionsUpdates: input.Status.Get().GetTransactionsUpdates(),
Auth: input.Status.Get().GetAuth(),
Identity: input.Status.Get().GetIdentity(),
InvestmentsUpdates: input.Status.Get().GetInvestmentsUpdates(),
LiabilitiesUpdates: input.Status.Get().GetLiabilitiesUpdates(),
Liabilities: input.Status.Get().GetLiabilities(),
Investments: input.Status.Get().GetInvestments(),
},
}
}

Expand Down

0 comments on commit e9ecb6b

Please sign in to comment.