Skip to content

testing autogen #2571

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
43 changes: 26 additions & 17 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -1759,37 +1759,46 @@ func (db database) GetBountiesLeaderboard() []LeaderData {
ms := []BountyLeaderboard{}
var users = []LeaderData{}

db.db.Raw(`SELECT t1.owner_pubkey, total_bounties_completed, total_sats_earned FROM
(SELECT assignee as owner_pubkey,
COUNT(assignee) as total_bounties_completed
From bounty
where paid=true and assignee != ''
GROUP BY assignee) t1
Right Join
(SELECT assignee as owner_pubkey,
SUM(CAST(price as integer)) as total_sats_earned
From bounty
where paid=true and assignee != ''
GROUP BY assignee) t2
ON t1.owner_pubkey = t2.owner_pubkey
ORDER by total_sats_earned DESC`).Find(&ms)
db.db.Raw(`SELECT
t2.owner_pubkey,
t1.total_bounties_completed,
t2.total_sats_earned,
IFNULL(t3.today_bounties_completed, 0) as today_bounties_completed
FROM
(SELECT assignee as owner_pubkey, COUNT(assignee) as total_bounties_completed
FROM bounty
WHERE paid = true AND assignee != ''
GROUP BY assignee) t1
RIGHT JOIN
(SELECT assignee as owner_pubkey, SUM(CAST(price as integer)) as total_sats_earned
FROM bounty
WHERE paid = true AND assignee != ''
GROUP BY assignee) t2
ON t1.owner_pubkey = t2.owner_pubkey
LEFT JOIN
(SELECT assignee as owner_pubkey, COUNT(assignee) as today_bounties_completed
FROM bounty
WHERE paid = true AND assignee != '' AND DATE(created_at) = CURRENT_DATE
GROUP BY assignee) t3
ON t2.owner_pubkey = t3.owner_pubkey
ORDER BY t2.total_sats_earned DESC`).Find(&ms)

for _, val := range ms {
var newLeader = make(map[string]interface{})
found, index := GetLeaderData(users, val.Owner_pubkey)

if found == -1 {
newLeader["owner_pubkey"] = val.Owner_pubkey
newLeader["total_bounties_completed"] = val.Total_bounties_completed
newLeader["total_sats_earned"] = val.Total_sats_earned

newLeader["today_bounties_completed"] = val.Today_bounties_completed // NEW FIELD
users = append(users, newLeader)
} else {
total_bounties := users[index]["total_bounties_completed"].(uint)
total_sats := users[index]["total_sats_earned"].(uint)

today := users[index]["today_bounties_completed"].(uint)
users[index]["total_bounties_completed"] = total_bounties + val.Total_bounties_completed
users[index]["total_sats_earned"] = total_sats + val.Total_sats_earned
users[index]["today_bounties_completed"] = today + val.Today_bounties_completed
}
}
return users
Expand Down
1 change: 1 addition & 0 deletions db/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ type BountyLeaderboard struct {
Owner_pubkey string `json:"owner_pubkey"`
Total_bounties_completed uint `json:"total_bounties_completed"`
Total_sats_earned uint `json:"total_sats_earned"`
Today_bounties_completed uint `json:"today_bounties_completed"` // NEW FIELD
}

type YoutubeDownload struct {
Expand Down
Loading