Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit eff1cc1

Browse files
committed
webui: Move retrieving star and watch status to DBDetails function
Instead of querying the watch and star status of a database in each web page manually, add the code to the DBDetails function. Basically every call of the DBDetails function is followed by querying the watch and star status anyway. Arguably this information is part of the database details anyway because they are always presented from the perspective of the currently logged in user.
1 parent eef1fb7 commit eff1cc1

File tree

5 files changed

+16
-214
lines changed

5 files changed

+16
-214
lines changed

common/postgresql.go

+12
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,18 @@ func DBDetails(DB *SQLiteDBinfo, loggedInUser, dbOwner, dbFolder, dbName, commit
681681
return err
682682
}
683683

684+
// Check if the database was starred by the logged in user
685+
DB.Info.MyStar, err = CheckDBStarred(loggedInUser, dbOwner, dbFolder, dbName)
686+
if err != nil {
687+
return err
688+
}
689+
690+
// Check if the database is being watched by the logged in user
691+
DB.Info.MyWatch, err = CheckDBWatched(loggedInUser, dbOwner, dbFolder, dbName)
692+
if err != nil {
693+
return err
694+
}
695+
684696
return nil
685697
}
686698

common/types.go

+2
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ type DBInfo struct {
231231
Licence string
232232
LicenceURL string
233233
MRs int
234+
MyStar bool
235+
MyWatch bool
234236
OneLineDesc string
235237
Owner string
236238
Public bool

webui/pages.go

-196
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ func branchesPage(w http.ResponseWriter, r *http.Request) {
5050
Branches []brEntry
5151
DB com.SQLiteDBinfo
5252
DefaultBranch string
53-
MyStar bool
54-
MyWatch bool
5553
PageMeta PageMetaInfo
5654
}
5755
pageData.PageMeta.Title = "Branch list"
@@ -76,20 +74,6 @@ func branchesPage(w http.ResponseWriter, r *http.Request) {
7674
return
7775
}
7876

79-
// Check if the database was starred by the logged in user
80-
pageData.MyStar, err = com.CheckDBStarred(pageData.PageMeta.LoggedInUser, dbName.Owner, dbName.Folder, dbName.Database)
81-
if err != nil {
82-
errorPage(w, r, http.StatusInternalServerError, "Couldn't retrieve latest social stats")
83-
return
84-
}
85-
86-
// Check if the database is being watched by the logged in user
87-
pageData.MyWatch, err = com.CheckDBWatched(pageData.PageMeta.LoggedInUser, dbName.Owner, dbName.Folder, dbName.Database)
88-
if err != nil {
89-
errorPage(w, r, http.StatusInternalServerError, "Couldn't retrieve database watch status")
90-
return
91-
}
92-
9377
// Read the branch heads list from the database
9478
branches, err := com.GetBranches(dbName.Owner, dbName.Folder, dbName.Database)
9579
if err != nil {
@@ -149,8 +133,6 @@ func commitsPage(w http.ResponseWriter, r *http.Request) {
149133
Branches []string
150134
DB com.SQLiteDBinfo
151135
History []HistEntry
152-
MyStar bool
153-
MyWatch bool
154136
PageMeta PageMetaInfo
155137
}
156138

@@ -183,20 +165,6 @@ func commitsPage(w http.ResponseWriter, r *http.Request) {
183165
return
184166
}
185167

186-
// Check if the database was starred by the logged in user
187-
pageData.MyStar, err = com.CheckDBStarred(pageData.PageMeta.LoggedInUser, dbName.Owner, dbName.Folder, dbName.Database)
188-
if err != nil {
189-
errorPage(w, r, http.StatusInternalServerError, "Couldn't retrieve latest social stats")
190-
return
191-
}
192-
193-
// Check if the database is being watched by the logged in user
194-
pageData.MyWatch, err = com.CheckDBWatched(pageData.PageMeta.LoggedInUser, dbName.Owner, dbName.Folder, dbName.Database)
195-
if err != nil {
196-
errorPage(w, r, http.StatusInternalServerError, "Couldn't retrieve database watch status")
197-
return
198-
}
199-
200168
// Read the branch heads list from the database
201169
branches, err := com.GetBranches(dbName.Owner, dbName.Folder, dbName.Database)
202170
if err != nil {
@@ -346,8 +314,6 @@ func comparePage(w http.ResponseWriter, r *http.Request) {
346314
DestFolder string
347315
DestOwner string
348316
Forks []com.ForkEntry
349-
MyStar bool
350-
MyWatch bool
351317
PageMeta PageMetaInfo
352318
SourceDBBranches []string
353319
SourceDBDefaultBranch string
@@ -444,20 +410,6 @@ func comparePage(w http.ResponseWriter, r *http.Request) {
444410
return
445411
}
446412

447-
// Check if the database was starred by the logged in user
448-
pageData.MyStar, err = com.CheckDBStarred(pageData.PageMeta.LoggedInUser, dbName.Owner, dbName.Folder, dbName.Database)
449-
if err != nil {
450-
errorPage(w, r, http.StatusInternalServerError, "Couldn't retrieve latest social stats")
451-
return
452-
}
453-
454-
// Check if the database is being watched by the logged in user
455-
pageData.MyWatch, err = com.CheckDBWatched(pageData.PageMeta.LoggedInUser, dbName.Owner, dbName.Folder, dbName.Database)
456-
if err != nil {
457-
errorPage(w, r, http.StatusInternalServerError, "Couldn't retrieve database watch status")
458-
return
459-
}
460-
461413
// If the initially chosen source and destinations can be directly applied, fill out the initial commit list entries
462414
// for display to the user
463415
ancestorID, cList, errType, err := com.GetCommonAncestorCommits(dbName.Owner, dbName.Folder, dbName.Database,
@@ -593,8 +545,6 @@ func contributorsPage(w http.ResponseWriter, r *http.Request) {
593545
var pageData struct {
594546
Contributors map[string]AuthorEntry
595547
DB com.SQLiteDBinfo
596-
MyStar bool
597-
MyWatch bool
598548
PageMeta PageMetaInfo
599549
}
600550
pageData.PageMeta.Title = "Contributors"
@@ -619,20 +569,6 @@ func contributorsPage(w http.ResponseWriter, r *http.Request) {
619569
return
620570
}
621571

622-
// Check if the database was starred by the logged in user
623-
pageData.MyStar, err = com.CheckDBStarred(pageData.PageMeta.LoggedInUser, dbName.Owner, dbName.Folder, dbName.Database)
624-
if err != nil {
625-
errorPage(w, r, http.StatusInternalServerError, "Couldn't retrieve latest social stats")
626-
return
627-
}
628-
629-
// Check if the database is being watched by the logged in user
630-
pageData.MyWatch, err = com.CheckDBWatched(pageData.PageMeta.LoggedInUser, dbName.Owner, dbName.Folder, dbName.Database)
631-
if err != nil {
632-
errorPage(w, r, http.StatusInternalServerError, "Couldn't retrieve database watch status")
633-
return
634-
}
635-
636572
// Read the commit list from the database
637573
commitList, err := com.GetCommitList(dbName.Owner, dbName.Folder, dbName.Database)
638574
if err != nil {
@@ -755,8 +691,6 @@ func createBranchPage(w http.ResponseWriter, r *http.Request) {
755691
func createDiscussionPage(w http.ResponseWriter, r *http.Request) {
756692
var pageData struct {
757693
DB com.SQLiteDBinfo
758-
MyStar bool
759-
MyWatch bool
760694
PageMeta PageMetaInfo
761695
}
762696
pageData.PageMeta.Title = "Create new discussion"
@@ -788,20 +722,6 @@ func createDiscussionPage(w http.ResponseWriter, r *http.Request) {
788722
return
789723
}
790724

791-
// Check if the database was starred by the logged in user
792-
pageData.MyStar, err = com.CheckDBStarred(pageData.PageMeta.LoggedInUser, dbName.Owner, dbName.Folder, dbName.Database)
793-
if err != nil {
794-
errorPage(w, r, http.StatusInternalServerError, "Couldn't retrieve latest social stats")
795-
return
796-
}
797-
798-
// Check if the database is being watched by the logged in user
799-
pageData.MyWatch, err = com.CheckDBWatched(pageData.PageMeta.LoggedInUser, dbName.Owner, dbName.Folder, dbName.Database)
800-
if err != nil {
801-
errorPage(w, r, http.StatusInternalServerError, "Couldn't retrieve database watch status")
802-
return
803-
}
804-
805725
// Render the page
806726
t := tmpl.Lookup("createDiscussionPage")
807727
err = t.Execute(w, pageData)
@@ -880,8 +800,6 @@ func databasePage(w http.ResponseWriter, r *http.Request, dbOwner string, dbFold
880800
var pageData struct {
881801
Data com.SQLiteRecordSet
882802
DB com.SQLiteDBinfo
883-
MyStar bool
884-
MyWatch bool
885803
PageMeta PageMetaInfo
886804
Config com.TomlConfig // FIXME: This seems silly to include here, when we just need to provide the server/port info
887805
}
@@ -1106,20 +1024,6 @@ func databasePage(w http.ResponseWriter, r *http.Request, dbOwner string, dbFold
11061024
return
11071025
}
11081026

1109-
// Check if the database was starred by the logged in user
1110-
myStar, err := com.CheckDBStarred(pageData.PageMeta.LoggedInUser, dbOwner, dbFolder, dbName)
1111-
if err != nil {
1112-
errorPage(w, r, http.StatusInternalServerError, "Couldn't retrieve database star status")
1113-
return
1114-
}
1115-
1116-
// Check if the database is being watched by the logged in user
1117-
myWatch, err := com.CheckDBWatched(pageData.PageMeta.LoggedInUser, dbOwner, dbFolder, dbName)
1118-
if err != nil {
1119-
errorPage(w, r, http.StatusInternalServerError, "Couldn't retrieve database watch status")
1120-
return
1121-
}
1122-
11231027
// If a specific table wasn't requested, use the user specified default (if present)
11241028
if dbTable == "" {
11251029
// Ensure the default table name validates. This catches a case where a database was uploaded with an invalid
@@ -1241,10 +1145,6 @@ func databasePage(w http.ResponseWriter, r *http.Request, dbOwner string, dbFold
12411145
pageData.DB.Info.Branch = branchName
12421146
pageData.DB.Info.Commits = branchHeads[branchName].CommitCount
12431147

1244-
// Update database star and watch status for the logged in user
1245-
pageData.MyStar = myStar
1246-
pageData.MyWatch = myWatch
1247-
12481148
// Render the full description as markdown
12491149
pageData.DB.Info.FullDesc = string(gfm.Markdown([]byte(pageData.DB.Info.FullDesc)))
12501150

@@ -1277,8 +1177,6 @@ func diffPage(w http.ResponseWriter, r *http.Request) {
12771177
Diffs com.Diffs
12781178
ColumnNamesBefore map[string][]string
12791179
ColumnNamesAfter map[string][]string
1280-
MyStar bool
1281-
MyWatch bool
12821180
PageMeta PageMetaInfo
12831181
}
12841182

@@ -1316,20 +1214,6 @@ func diffPage(w http.ResponseWriter, r *http.Request) {
13161214
return
13171215
}
13181216

1319-
// Check if the database was starred by the logged in user
1320-
pageData.MyStar, err = com.CheckDBStarred(pageData.PageMeta.LoggedInUser, dbName.Owner, dbName.Folder, dbName.Database)
1321-
if err != nil {
1322-
errorPage(w, r, http.StatusInternalServerError, "Couldn't retrieve latest social stats")
1323-
return
1324-
}
1325-
1326-
// Check if the database is being watched by the logged in user
1327-
pageData.MyWatch, err = com.CheckDBWatched(pageData.PageMeta.LoggedInUser, dbName.Owner, dbName.Folder, dbName.Database)
1328-
if err != nil {
1329-
errorPage(w, r, http.StatusInternalServerError, "Couldn't retrieve database watch status")
1330-
return
1331-
}
1332-
13331217
// Retrieve the diffs for these commits
13341218
pageData.Diffs, err = com.Diff(dbName.Owner, "/", dbName.Database, commitA, dbName.Owner, "/", dbName.Database, commitB, pageData.PageMeta.LoggedInUser, com.NoMerge, true)
13351219
if err != nil {
@@ -1387,8 +1271,6 @@ func discussPage(w http.ResponseWriter, r *http.Request) {
13871271
DB com.SQLiteDBinfo
13881272
DiscussionList []com.DiscussionEntry
13891273
SelectedID int
1390-
MyStar bool
1391-
MyWatch bool
13921274
PageMeta PageMetaInfo
13931275
}
13941276

@@ -1425,20 +1307,6 @@ func discussPage(w http.ResponseWriter, r *http.Request) {
14251307
return
14261308
}
14271309

1428-
// Check if the database was starred by the logged in user
1429-
pageData.MyStar, err = com.CheckDBStarred(pageData.PageMeta.LoggedInUser, dbName.Owner, dbName.Folder, dbName.Database)
1430-
if err != nil {
1431-
errorPage(w, r, http.StatusInternalServerError, "Couldn't retrieve latest social stats")
1432-
return
1433-
}
1434-
1435-
// Check if the database is being watched by the logged in user
1436-
pageData.MyWatch, err = com.CheckDBWatched(pageData.PageMeta.LoggedInUser, dbName.Owner, dbName.Folder, dbName.Database)
1437-
if err != nil {
1438-
errorPage(w, r, http.StatusInternalServerError, "Couldn't retrieve database watch status")
1439-
return
1440-
}
1441-
14421310
// Retrieve the list of discussions for this database
14431311
pageData.DiscussionList, err = com.Discussions(dbName.Owner, dbName.Folder, dbName.Database, com.DISCUSSION, pageData.SelectedID)
14441312
if err != nil {
@@ -1619,8 +1487,6 @@ func mergePage(w http.ResponseWriter, r *http.Request) {
16191487
StatusMessageColour string
16201488
SourceBranchOK bool
16211489
SourceDBOK bool
1622-
MyStar bool
1623-
MyWatch bool
16241490
}
16251491

16261492
pageData.PageMeta.PageSection = "db_merge"
@@ -1657,20 +1523,6 @@ func mergePage(w http.ResponseWriter, r *http.Request) {
16571523
return
16581524
}
16591525

1660-
// Check if the database was starred by the logged in user
1661-
pageData.MyStar, err = com.CheckDBStarred(pageData.PageMeta.LoggedInUser, dbName.Owner, dbName.Folder, dbName.Database)
1662-
if err != nil {
1663-
errorPage(w, r, http.StatusInternalServerError, "Couldn't retrieve latest social stats")
1664-
return
1665-
}
1666-
1667-
// Check if the database is being watched by the logged in user
1668-
pageData.MyWatch, err = com.CheckDBWatched(pageData.PageMeta.LoggedInUser, dbName.Owner, dbName.Folder, dbName.Database)
1669-
if err != nil {
1670-
errorPage(w, r, http.StatusInternalServerError, "Couldn't retrieve database watch status")
1671-
return
1672-
}
1673-
16741526
// Retrieve the list of MRs for this database
16751527
pageData.MRList, err = com.Discussions(dbName.Owner, dbName.Folder, dbName.Database, com.MERGE_REQUEST, pageData.SelectedID)
16761528
if err != nil {
@@ -2075,8 +1927,6 @@ func releasesPage(w http.ResponseWriter, r *http.Request) {
20751927
}
20761928
var pageData struct {
20771929
DB com.SQLiteDBinfo
2078-
MyStar bool
2079-
MyWatch bool
20801930
PageMeta PageMetaInfo
20811931
ReleaseList map[string]relEntry
20821932
}
@@ -2102,20 +1952,6 @@ func releasesPage(w http.ResponseWriter, r *http.Request) {
21021952
return
21031953
}
21041954

2105-
// Check if the database was starred by the logged in user
2106-
pageData.MyStar, err = com.CheckDBStarred(pageData.PageMeta.LoggedInUser, dbName.Owner, dbName.Folder, dbName.Database)
2107-
if err != nil {
2108-
errorPage(w, r, http.StatusInternalServerError, "Couldn't retrieve latest social stats")
2109-
return
2110-
}
2111-
2112-
// Check if the database is being watched by the logged in user
2113-
pageData.MyWatch, err = com.CheckDBWatched(pageData.PageMeta.LoggedInUser, dbName.Owner, dbName.Folder, dbName.Database)
2114-
if err != nil {
2115-
errorPage(w, r, http.StatusInternalServerError, "Couldn't retrieve database watch status")
2116-
return
2117-
}
2118-
21191955
// Retrieve the release list for the database
21201956
releases, err := com.GetReleases(dbName.Owner, dbName.Folder, dbName.Database)
21211957
if err != nil {
@@ -2232,8 +2068,6 @@ func settingsPage(w http.ResponseWriter, r *http.Request) {
22322068
FullDescRendered string
22332069
Licences map[string]com.LicenceEntry
22342070
NumLicences int
2235-
MyStar bool
2236-
MyWatch bool
22372071
PageMeta PageMetaInfo
22382072
Shares map[string]com.ShareDatabasePermissions
22392073
}
@@ -2265,20 +2099,6 @@ func settingsPage(w http.ResponseWriter, r *http.Request) {
22652099
return
22662100
}
22672101

2268-
// Check if the database was starred by the logged in user
2269-
pageData.MyStar, err = com.CheckDBStarred(pageData.PageMeta.LoggedInUser, dbName.Owner, dbName.Folder, dbName.Database)
2270-
if err != nil {
2271-
errorPage(w, r, http.StatusInternalServerError, "Couldn't retrieve latest social stats")
2272-
return
2273-
}
2274-
2275-
// Check if the database is being watched by the logged in user
2276-
pageData.MyWatch, err = com.CheckDBWatched(pageData.PageMeta.LoggedInUser, dbName.Owner, dbName.Folder, dbName.Database)
2277-
if err != nil {
2278-
errorPage(w, r, http.StatusInternalServerError, "Couldn't retrieve database watch status")
2279-
return
2280-
}
2281-
22822102
// Retrieve the database details
22832103
err = com.DBDetails(&pageData.DB, pageData.PageMeta.LoggedInUser, dbName.Owner, dbName.Folder, dbName.Database, "")
22842104
if err != nil {
@@ -2473,8 +2293,6 @@ func tagsPage(w http.ResponseWriter, r *http.Request) {
24732293
}
24742294
var pageData struct {
24752295
DB com.SQLiteDBinfo
2476-
MyStar bool
2477-
MyWatch bool
24782296
PageMeta PageMetaInfo
24792297
TagList map[string]tgEntry
24802298
}
@@ -2500,20 +2318,6 @@ func tagsPage(w http.ResponseWriter, r *http.Request) {
25002318
return
25012319
}
25022320

2503-
// Check if the database was starred by the logged in user
2504-
pageData.MyStar, err = com.CheckDBStarred(pageData.PageMeta.LoggedInUser, dbName.Owner, dbName.Folder, dbName.Database)
2505-
if err != nil {
2506-
errorPage(w, r, http.StatusInternalServerError, "Couldn't retrieve latest social stats")
2507-
return
2508-
}
2509-
2510-
// Check if the database is being watched by the logged in user
2511-
pageData.MyWatch, err = com.CheckDBWatched(pageData.PageMeta.LoggedInUser, dbName.Owner, dbName.Folder, dbName.Database)
2512-
if err != nil {
2513-
errorPage(w, r, http.StatusInternalServerError, "Couldn't retrieve database watch status")
2514-
return
2515-
}
2516-
25172321
// Retrieve the tag list for the database
25182322
tags, err := com.GetTags(dbName.Owner, dbName.Folder, dbName.Database)
25192323
if err != nil {

0 commit comments

Comments
 (0)