Skip to content

Commit

Permalink
fix query
Browse files Browse the repository at this point in the history
  • Loading branch information
insipx committed Apr 24, 2024
1 parent ca41698 commit 171003e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
21 changes: 12 additions & 9 deletions pkg/mls/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,32 +170,35 @@ func (s *Store) GetInboxLogs(ctx context.Context, batched_req *identity.GetIdent
}, nil
}

type GroupedAddressLogEntry struct {
Address string
InboxId string
MaxAssociationSequenceId uint64 `bun:max_association_sequence_id",notnull"`

Check failure on line 176 in pkg/mls/store/store.go

View workflow job for this annotation

GitHub Actions / Lint

structtag: struct field tag `bun:max_association_sequence_id",notnull"` not compatible with reflect.StructTag.Get: bad syntax for struct tag value (govet)
}

func (s *Store) GetInboxIds(ctx context.Context, req *identity.GetInboxIdsRequest) (*identity.GetInboxIdsResponse, error) {

addresses := []string{}
for _, request := range req.Requests {
addresses = append(addresses, request.GetAddress())
}
s.log.Info("GetInboxIds", zap.Strings("addresses", addresses))

db_log_entries := make([]*AddressLogEntry, 0)
db_log_entries := make([]*GroupedAddressLogEntry, 0)

// maybe restrict select to only fields in groupby?
err := s.db.NewSelect().
Model(&db_log_entries).
Model((*AddressLogEntry)(nil)).
ColumnExpr("address, inbox_id, MAX(association_sequence_id) as max_association_sequence_id").
Where("address IN (?)", bun.In(addresses)).
Where("revocation_sequence_id IS NULL OR revocation_sequence_id < association_sequence_id").
Group("address", "inbox_id", "association_sequence_id", "revocation_sequence_id").
Order("association_sequence_id DESC").
Scan(ctx)
Group("address", "inbox_id").
OrderExpr("MAX(association_sequence_id) ASC").
Scan(ctx, &db_log_entries)

s.log.Error("Db", zap.Any("err", err))
if err != nil {
return nil, err
}

s.log.Info("Db", zap.Any("db_log_entries", db_log_entries))

out := make([]*identity.GetInboxIdsResponse_Response, len(addresses))

for index, address := range addresses {
Expand Down
9 changes: 8 additions & 1 deletion pkg/mls/store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,14 @@ func TestInboxIds(t *testing.T) {
seq = uint64(5)
err = InsertAddressLog(store, "address", "correct_inbox2", &seq, nil)
resp, _ = store.GetInboxIds(context.Background(), req)
t.Log(resp)
require.Equal(t, "correct_inbox2", *resp.Responses[0].InboxId)

reqs = append(reqs, &identity.GetInboxIdsRequest_Request{Address: "address2"})
req = &identity.GetInboxIdsRequest{
Requests: reqs,
}
seq, rev = uint64(8), uint64(2)
err = InsertAddressLog(store, "address2", "inbox2", &seq, &rev)
resp, _ = store.GetInboxIds(context.Background(), req)
require.Equal(t, "inbox2", *resp.Responses[1].InboxId)
}

0 comments on commit 171003e

Please sign in to comment.