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

Commit 38e4014

Browse files
committed
webui: Fix a91ed9f
This fixes some issues introduced in a previous commit for deduplicating code for live databases. The issue here was that the common database header now relies on an information whether the current database is a live database. For mose pages this information was not yet provided. Instead of providing this information for all pages by adding more code, this commit moves the deduplication forward by updating the existing functions to include this information.
1 parent a91ed9f commit 38e4014

File tree

6 files changed

+20
-60
lines changed

6 files changed

+20
-60
lines changed

common/postgresql.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ func DBDetails(DB *SQLiteDBinfo, loggedInUser, dbOwner, dbFolder, dbName, commit
596596
SELECT db.date_created, db.last_modified, db.watchers, db.stars, db.discussions, db.merge_requests,
597597
$4::text AS commit_id, db.commit_list->$4::text->'tree'->'entries'->0 AS db_entry,
598598
db.branches, db.release_count, db.contributors, db.one_line_description, db.full_description,
599-
db.default_table, db.public, db.source_url, db.tags, db.default_branch
599+
db.default_table, db.public, db.source_url, db.tags, coalesce(db.default_branch, ''), db.live_db
600600
FROM sqlite_databases AS db
601601
WHERE db.user_id = (
602602
SELECT user_id
@@ -614,7 +614,7 @@ func DBDetails(DB *SQLiteDBinfo, loggedInUser, dbOwner, dbFolder, dbName, commit
614614
&DB.Info.CommitID,
615615
&DB.Info.DBEntry,
616616
&DB.Info.Branches, &DB.Info.Releases, &DB.Info.Contributors, &oneLineDesc, &fullDesc, &defTable,
617-
&DB.Info.Public, &sourceURL, &DB.Info.Tags, &DB.Info.DefaultBranch)
617+
&DB.Info.Public, &sourceURL, &DB.Info.Tags, &DB.Info.DefaultBranch, &DB.Info.IsLive)
618618

619619
if err != nil {
620620
log.Printf("Error when retrieving database details: %v\n", err.Error())

common/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ type DBInfo struct {
222222
Folder string
223223
Forks int
224224
FullDesc string
225+
IsLive bool
225226
LastModified time.Time
226227
Licence string
227228
LicenceURL string

webui/pages.go

Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,6 @@ func databasePage(w http.ResponseWriter, r *http.Request, dbOwner string, dbFold
819819
MyStar bool
820820
MyWatch bool
821821
Config com.TomlConfig // FIXME: This seems silly to include here, when we just need to provide the server/port info
822-
IsLive bool
823822
}
824823

825824
pageData.Meta.PageSection = "db_data"
@@ -948,16 +947,15 @@ func databasePage(w http.ResponseWriter, r *http.Request, dbOwner string, dbFold
948947
}
949948

950949
// Check if this is a live database
951-
var liveNode string
952-
pageData.IsLive, liveNode, err = com.CheckDBLive(dbOwner, dbFolder, dbName)
950+
isLive, liveNode, err := com.CheckDBLive(dbOwner, dbFolder, dbName)
953951
if err != nil {
954952
errorPage(w, r, http.StatusInternalServerError, err.Error())
955953
return
956954
}
957955

958956
// Only standard databases have commits, branches, tags (etC)
959957
branchHeads := make(map[string]com.BranchEntry)
960-
if !pageData.IsLive {
958+
if !isLive {
961959
// If a specific commit was requested, make sure it exists in the database commit history
962960
if commitID != "" {
963961
commitList, err := com.GetCommitList(dbOwner, dbFolder, dbName)
@@ -1030,52 +1028,13 @@ func databasePage(w http.ResponseWriter, r *http.Request, dbOwner string, dbFold
10301028
return
10311029
}
10321030
}
1031+
}
10331032

1034-
// Retrieve the database details
1035-
err = com.DBDetails(&pageData.DB, pageData.Meta.LoggedInUser, dbOwner, dbFolder, dbName, commitID)
1036-
if err != nil {
1037-
errorPage(w, r, http.StatusBadRequest, err.Error())
1038-
return
1039-
}
1040-
} else {
1041-
// FIXME: We need an equivalent of com.DBDetails() for live databases
1042-
pageData.DB = com.SQLiteDBinfo{
1043-
Info: com.DBInfo{
1044-
Branch: "",
1045-
Branches: 0,
1046-
BranchList: nil,
1047-
Commits: 0,
1048-
CommitID: "",
1049-
Contributors: 1, // 1 makes sense here, as we don't yet support sharing live databases
1050-
Database: dbName,
1051-
DateCreated: time.Time{},
1052-
DBEntry: com.DBTreeEntry{},
1053-
DefaultBranch: "",
1054-
DefaultTable: "",
1055-
Discussions: 0,
1056-
Downloads: 0,
1057-
Folder: "",
1058-
Forks: 0,
1059-
FullDesc: "",
1060-
LastModified: time.Time{},
1061-
Licence: "",
1062-
LicenceURL: "",
1063-
MRs: 0,
1064-
OneLineDesc: "",
1065-
Public: false,
1066-
RepoModified: time.Time{},
1067-
Releases: 0,
1068-
SHA256: "",
1069-
Size: 0,
1070-
SourceURL: "",
1071-
Stars: 0,
1072-
Tables: nil,
1073-
Tags: 0,
1074-
Views: 0,
1075-
Watchers: 0,
1076-
},
1077-
MaxRows: 0,
1078-
}
1033+
// Retrieve the database details
1034+
err = com.DBDetails(&pageData.DB, pageData.Meta.LoggedInUser, dbOwner, dbFolder, dbName, commitID)
1035+
if err != nil {
1036+
errorPage(w, r, http.StatusBadRequest, err.Error())
1037+
return
10791038
}
10801039

10811040
// Get the latest discussion and merge request count directly from PG, skipping the ones (incorrectly) stored in memcache
@@ -1125,7 +1084,7 @@ func databasePage(w http.ResponseWriter, r *http.Request, dbOwner string, dbFold
11251084
}
11261085

11271086
// If it's a standard database then we query it directly, otherwise we query it via our AMQP backend
1128-
if !pageData.IsLive {
1087+
if !isLive {
11291088
bucket := pageData.DB.Info.DBEntry.Sha256[:com.MinioFolderChars]
11301089
id := pageData.DB.Info.DBEntry.Sha256[com.MinioFolderChars:]
11311090
pageData.DB.Info.Tables, pageData.DB.Info.DefaultTable, pageData.Data, _, err =
@@ -1235,7 +1194,7 @@ func databasePage(w http.ResponseWriter, r *http.Request, dbOwner string, dbFold
12351194
pageData.DB.Info.MRs = currentMRs
12361195

12371196
// If this is a standard database, then cache the table row data
1238-
if !pageData.IsLive {
1197+
if !isLive {
12391198
rowCacheKey := com.TableRowsCacheKey(fmt.Sprintf("tablejson/%s/%s/%d", sortCol, sortDir, rowOffset),
12401199
pageData.Meta.LoggedInUser, dbOwner, dbFolder, dbName, commitID, dbTable, pageData.DB.MaxRows)
12411200
err = com.CacheData(rowCacheKey, pageData.Data, com.Conf.Memcache.DefaultCacheTime)

webui/templates/database.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
</div>
3333
</div>
3434
[[ end ]]
35-
[[ if eq .IsLive false ]]
35+
[[ if eq .DB.Info.IsLive false ]]
3636
<div class="row">
3737
<div class="col-md-12">
3838
<div style="border: 1px solid #DDD; border-radius: 7px; margin-bottom: 10px;">
@@ -85,7 +85,7 @@
8585
</li>
8686
</ul>
8787
</div>
88-
[[ if eq .IsLive false ]]
88+
[[ if eq .DB.Info.IsLive false ]]
8989
<div class="btn-group" uib-dropdown keyboard-nav="true">
9090
<button id="viewbranch" type="button" class="btn" data-cy="branchname"><span style="font-weight: bold">Branch:</span> {{ meta.Branch }}</button>
9191

@@ -99,14 +99,14 @@
9999
</ul>
100100
</div>
101101
[[ end ]]
102-
[[ if and (.Meta.LoggedInUser) (eq .IsLive false) ]]
102+
[[ if and (.Meta.LoggedInUser) (eq .DB.Info.IsLive false) ]]
103103
<a href="/compare/[[ .Meta.Owner ]]/[[ .Meta.Database ]]" class="btn btn-primary" data-cy="newmrbtn">New Merge Request</a>
104104
<button class="btn btn-primary" ng-click="uploadForm()" data-cy="uploadbtn">Upload database</button>
105105
[[ end ]]
106106
</div>
107107
</span>
108108
</div>
109-
[[ if eq .IsLive false ]]
109+
[[ if eq .DB.Info.IsLive false ]]
110110
<div class="col-md-4">
111111
<span class="pull-right">
112112
<div class="btn-group" uib-dropdown keyboard-nav="true">

webui/templates/script_db_header.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
pageSection: "[[ .Meta.PageSection ]]",
66
owner: "[[ .Meta.Owner ]]",
77
database: "[[ .Meta.Database ]]",
8-
isLive: [[ .IsLive ]],
8+
isLive: [[ .DB.Info.IsLive ]],
99

1010
publicDb: [[ .DB.Info.Public ]],
1111
repoModified: [[ .DB.Info.RepoModified ]],

webui/vis.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,8 @@ func visualisePage(w http.ResponseWriter, r *http.Request) {
324324

325325
// Update database star and watch status for the logged in user
326326
// FIXME: Add Cypress tests for this, to ensure moving the code above isn't screwing anything up (especially cacheing)
327-
//pageData.MyStar = myStar
328-
//pageData.MyWatch = myWatch
327+
//pageData.MyStar = myStar
328+
//pageData.MyWatch = myWatch
329329

330330
// Render the visualisation page
331331
pageData.Meta.PageSection = "db_vis"

0 commit comments

Comments
 (0)