Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend DAO object with active proposals ids #76

Merged
merged 5 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added
- Extend DAO object with active proposals ids

## [0.2.7] - 2024-10-07

### Fixed
Expand Down
7 changes: 5 additions & 2 deletions internal/dao/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,11 @@ type Dao struct {
ActivitySince int
VotersCount int
PopularityIndex float64
ActiveVotes int
Verified bool
// ActiveVotes the number of active proposals
ActiveVotes int
// ActiveProposalsIDs the list of active proposals identifiers
ActiveProposalsIDs []string `gorm:"serializer:json"`
Verified bool
}

func convertToCoreEvent(dao Dao) events.DaoPayload {
Expand Down
18 changes: 13 additions & 5 deletions internal/dao/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ type DaoList struct {
TotalCount int64
}

// todo: add order by
func (r *Repo) GetByFilters(filters []Filter, count bool) (DaoList, error) {
db := r.db.Model(&Dao{})
for _, f := range filters {
Expand Down Expand Up @@ -141,11 +140,17 @@ where daos.id = ?
}

func (r *Repo) UpdateActiveVotes(id uuid.UUID) error {
var (
dummy = Dao{}
_ = dummy.ActiveVotes
_ = dummy.ActiveProposalsIDs
)

return r.db.Exec(`
update daos
set active_votes = cnt.active_votes
set active_votes = cnt.active_votes, active_proposals_ids = cnt.list
from (
select count(*) as active_votes
select count(*) as active_votes, coalesce(json_agg(id), '[]') list
from proposals
where dao_id = ? and state = 'active' and spam is not true
) cnt
Expand All @@ -156,9 +161,12 @@ where daos.id = ?
func (r *Repo) UpdateActiveVotesAll() error {
return r.db.Exec(`
update daos
set active_votes = cnt.active_votes
set active_votes = cnt.active_votes, active_proposals_ids = cnt.list
from (
select dao_id, count(id) filter (where state = 'active' and spam is not true) as active_votes
select
dao_id,
count(id) filter (where state = 'active' and spam is not true) as active_votes,
coalesce(json_agg(id) filter (where state = 'active' and spam is not true), '[]') as list
from proposals
group by dao_id
) cnt
Expand Down
65 changes: 33 additions & 32 deletions internal/dao/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,38 +148,39 @@ func (s *Server) GetTopByCategories(ctx context.Context, req *storagepb.TopByCat

func convertDaoToAPI(dao *Dao) *storagepb.DaoInfo {
return &storagepb.DaoInfo{
Id: dao.ID.String(),
Alias: dao.OriginalID,
CreatedAt: timestamppb.New(dao.CreatedAt),
UpdatedAt: timestamppb.New(dao.UpdatedAt),
Name: dao.Name,
Private: dao.Private,
About: dao.About,
Avatar: dao.Avatar,
Terms: dao.Terms,
Location: dao.Location,
Website: dao.Website,
Twitter: dao.Twitter,
Github: dao.Github,
Coingeko: dao.Coingecko,
Email: dao.Email,
Network: dao.Network,
Symbol: dao.Symbol,
Skin: dao.Skin,
Domain: dao.Domain,
Strategies: convertStrategiesToAPI(dao.Strategies),
Voting: convertVotingToAPI(dao.Voting),
Categories: dao.Categories,
Treasuries: convertTreasuriesToAPI(dao.Treasures),
FollowersCount: uint64(dao.VotersCount),
ProposalsCount: uint64(dao.ProposalsCount),
Guidelines: dao.Guidelines,
Template: dao.Template,
ActivitySince: uint64(dao.ActivitySince),
VotersCount: uint64(dao.VotersCount),
ActiveVotes: uint64(dao.ActiveVotes),
Verified: dao.Verified,
PopularityIndex: dao.PopularityIndex,
Id: dao.ID.String(),
Alias: dao.OriginalID,
CreatedAt: timestamppb.New(dao.CreatedAt),
UpdatedAt: timestamppb.New(dao.UpdatedAt),
Name: dao.Name,
Private: dao.Private,
About: dao.About,
Avatar: dao.Avatar,
Terms: dao.Terms,
Location: dao.Location,
Website: dao.Website,
Twitter: dao.Twitter,
Github: dao.Github,
Coingeko: dao.Coingecko,
Email: dao.Email,
Network: dao.Network,
Symbol: dao.Symbol,
Skin: dao.Skin,
Domain: dao.Domain,
Strategies: convertStrategiesToAPI(dao.Strategies),
Voting: convertVotingToAPI(dao.Voting),
Categories: dao.Categories,
Treasuries: convertTreasuriesToAPI(dao.Treasures),
FollowersCount: uint64(dao.VotersCount),
ProposalsCount: uint64(dao.ProposalsCount),
Guidelines: dao.Guidelines,
Template: dao.Template,
ActivitySince: uint64(dao.ActivitySince),
VotersCount: uint64(dao.VotersCount),
ActiveVotes: uint64(dao.ActiveVotes),
Verified: dao.Verified,
PopularityIndex: dao.PopularityIndex,
ActiveProposalsIds: dao.ActiveProposalsIDs,
// TODO: parentID
}
}
Expand Down
4 changes: 0 additions & 4 deletions internal/ensresolver/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import (
"gorm.io/gorm/clause"
)

const (
defaultBatchSize = 100
)

type Repo struct {
db *gorm.DB
}
Expand Down
2 changes: 1 addition & 1 deletion protocol/storagepb/base.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading