appview: {db,issues}: remove unnecessary GetIssueId method #331

merged
opened by boltless.me targeting master from boltless.me/core: push-pslnqmxvulmp

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

Changed files
+7 -19
appview
db
issues
-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 - }) 712 - if err != nil { 713 - log.Println("failed to create issue", err) 714 - rp.pages.Notice(w, "issues", "Failed to create issue.") 715 - return 716 711 } 717 - 718 - issueId, err := db.GetIssueId(rp.db, f.RepoAt) 712 + err = db.NewIssue(tx, issue) 719 713 if err != nil { 720 - log.Println("failed to get issue id", err) 714 + log.Println("failed to create issue", err) 721 715 rp.pages.Notice(w, "issues", "Failed to create issue.") 722 716 return 723 717 } ··· 739 733 Title: title, 740 734 Body: &body, 741 735 Owner: user.Did, 742 - IssueId: int64(issueId), 736 + IssueId: int64(issue.IssueId), 743 737 }, 744 738 }, 745 739 }) ··· 749 743 return 750 744 } 751 745 752 - err = db.SetIssueAt(rp.db, f.RepoAt, issueId, resp.Uri) 746 + err = db.SetIssueAt(rp.db, f.RepoAt, issue.IssueId, resp.Uri) 753 747 if err != nil { 754 748 log.Println("failed to set issue at", err) 755 749 rp.pages.Notice(w, "issues", "Failed to create issue.") ··· 760 754 err = rp.posthog.Enqueue(posthog.Capture{ 761 755 DistinctId: user.Did, 762 756 Event: "new_issue", 763 - Properties: posthog.Properties{"repo_at": f.RepoAt.String(), "issue_id": issueId}, 757 + Properties: posthog.Properties{"repo_at": f.RepoAt.String(), "issue_id": issue.IssueId}, 764 758 }) 765 759 if err != nil { 766 760 log.Println("failed to enqueue posthog event:", err) 767 761 } 768 762 } 769 763 770 - rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", f.OwnerSlashRepo(), issueId)) 764 + rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", f.OwnerSlashRepo(), issue.IssueId)) 771 765 return 772 766 } 773 767 }