Skip to content

Commit

Permalink
latest
Browse files Browse the repository at this point in the history
  • Loading branch information
insipx committed Apr 25, 2024
1 parent 59aef68 commit a4ff301
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
22 changes: 14 additions & 8 deletions pkg/mls/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,24 @@ func (s *Store) GetInboxIds(ctx context.Context, req *identity.GetInboxIdsReques
addresses = append(addresses, request.GetAddress())
}

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

// maybe restrict select to only fields in groupby?
err := s.db.NewSelect().
Model((*AddressLogEntry)(nil)).
ColumnExpr("address, inbox_id, MAX(association_sequence_id) as max_association_sequence_id").
s.log.Info("Addresses", zap.Any("addresses", addresses))
subquery := s.db.NewSelect().
Column("address").
ColumnExpr("MAX(association_sequence_id) AS max_association_sequence_id").
Table("address_log").
Where("address IN (?)", bun.In(addresses)).
Where("revocation_sequence_id IS NULL OR revocation_sequence_id < association_sequence_id").
Group("address", "inbox_id").
OrderExpr("MAX(association_sequence_id) ASC").
Group("address")

err := s.db.NewSelect().
Column("a.address", "a.inbox_id", "a.association_sequence_id").
TableExpr("address_log AS a").
Join("INNER JOIN (?) AS b ON a.address = b.address AND a.association_sequence_id = b.max_association_sequence_id", subquery).
Scan(ctx, &db_log_entries)

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

if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions pkg/mls/store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@ func TestInboxIds(t *testing.T) {
Requests: reqs,
}
resp, _ := store.GetInboxIds(context.Background(), req)
t.Log(resp)

require.Equal(t, "correct", *resp.Responses[0].InboxId)

Expand Down

0 comments on commit a4ff301

Please sign in to comment.