Mirror of @tangled.org/core. Running on a Raspberry Pi Zero 2 (Please be gentle).
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

appview: {db,issues}: remove unnecessary `GetIssueId` method

As `issue.IssueId` is already retrieved from `NewIssue`, We don't need
`GetIssueId` to get last issue-id.
Using same, last inserted issue-id would be better.

Signed-off-by: Seongmin Lee <boltlessengineer@proton.me>

authored by

Seongmin Lee and committed by
Tangled
ec00705f f743574a

+7 -19
-6
appview/db/issues.go
··· 98 98 return issueAt, err 99 99 } 100 100 101 - func GetIssueId(e Execer, repoAt syntax.ATURI) (int, error) { 102 - var issueId int 103 - err := e.QueryRow(`select next_issue_id from repo_issue_seqs where repo_at = ?`, repoAt).Scan(&issueId) 104 - return issueId - 1, err 105 - } 106 - 107 101 func GetIssueOwnerDid(e Execer, repoAt syntax.ATURI, issueId int) (string, error) { 108 102 var ownerDid string 109 103 err := e.QueryRow(`select owner_did from issues where repo_at = ? and issue_id = ?`, repoAt, issueId).Scan(&ownerDid)
+7 -13
appview/issues/issues.go
··· 703 703 return 704 704 } 705 705 706 - err = db.NewIssue(tx, &db.Issue{ 706 + issue := &db.Issue{ 707 707 RepoAt: f.RepoAt, 708 708 Title: title, 709 709 Body: body, 710 710 OwnerDid: user.Did, 711 - }) 711 + } 712 + err = db.NewIssue(tx, issue) 712 713 if err != nil { 713 714 log.Println("failed to create issue", err) 714 - rp.pages.Notice(w, "issues", "Failed to create issue.") 715 - return 716 - } 717 - 718 - issueId, err := db.GetIssueId(rp.db, f.RepoAt) 719 - if err != nil { 720 - log.Println("failed to get issue id", err) 721 715 rp.pages.Notice(w, "issues", "Failed to create issue.") 722 716 return 723 717 } ··· 733 739 Title: title, 734 740 Body: &body, 735 741 Owner: user.Did, 736 - IssueId: int64(issueId), 742 + IssueId: int64(issue.IssueId), 737 743 }, 738 744 }, 739 745 }) ··· 743 749 return 744 750 } 745 751 746 - err = db.SetIssueAt(rp.db, f.RepoAt, issueId, resp.Uri) 752 + err = db.SetIssueAt(rp.db, f.RepoAt, issue.IssueId, resp.Uri) 747 753 if err != nil { 748 754 log.Println("failed to set issue at", err) 749 755 rp.pages.Notice(w, "issues", "Failed to create issue.") ··· 754 760 err = rp.posthog.Enqueue(posthog.Capture{ 755 761 DistinctId: user.Did, 756 762 Event: "new_issue", 757 - Properties: posthog.Properties{"repo_at": f.RepoAt.String(), "issue_id": issueId}, 763 + Properties: posthog.Properties{"repo_at": f.RepoAt.String(), "issue_id": issue.IssueId}, 758 764 }) 759 765 if err != nil { 760 766 log.Println("failed to enqueue posthog event:", err) 761 767 } 762 768 } 763 769 764 - rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", f.OwnerSlashRepo(), issueId)) 770 + rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", f.OwnerSlashRepo(), issue.IssueId)) 765 771 return 766 772 } 767 773 }