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

Commit 9a0a105

Browse files
committed
webui: Some fixes for the settings page for live databases
This adds some fixes to the settings page to make it work better with live databases. There are still too many remaining issues though to call is useful.
1 parent e4ae221 commit 9a0a105

File tree

1 file changed

+54
-15
lines changed

1 file changed

+54
-15
lines changed

webui/pages.go

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,23 +2235,62 @@ func settingsPage(w http.ResponseWriter, r *http.Request) {
22352235
return
22362236
}
22372237

2238-
// Get a handle from Minio for the database object
2239-
bkt := pageData.DB.Info.DBEntry.Sha256[:com.MinioFolderChars]
2240-
id := pageData.DB.Info.DBEntry.Sha256[com.MinioFolderChars:]
2241-
sdb, err := com.OpenSQLiteDatabase(bkt, id)
2242-
if err != nil {
2243-
errorPage(w, r, http.StatusInternalServerError, err.Error())
2244-
return
2245-
}
2238+
// If it's a standard database then we query it directly, otherwise we query it via our AMQP backend
2239+
if !pageData.DB.Info.IsLive {
2240+
// Get a handle from Minio for the database object
2241+
bkt := pageData.DB.Info.DBEntry.Sha256[:com.MinioFolderChars]
2242+
id := pageData.DB.Info.DBEntry.Sha256[com.MinioFolderChars:]
2243+
sdb, err := com.OpenSQLiteDatabase(bkt, id)
2244+
if err != nil {
2245+
errorPage(w, r, http.StatusInternalServerError, err.Error())
2246+
return
2247+
}
22462248

2247-
// Automatically close the SQLite database when this function finishes
2248-
defer sdb.Close()
2249+
// Automatically close the SQLite database when this function finishes
2250+
defer sdb.Close()
22492251

2250-
// Retrieve the list of tables in the database
2251-
pageData.DB.Info.Tables, err = com.TablesAndViews(sdb, fmt.Sprintf("%s%s%s", pageData.Meta.Owner, pageData.Meta.Folder, pageData.Meta.Database))
2252-
if err != nil {
2253-
errorPage(w, r, http.StatusInternalServerError, err.Error())
2254-
return
2252+
// Retrieve the list of tables in the database
2253+
pageData.DB.Info.Tables, err = com.TablesAndViews(sdb, fmt.Sprintf("%s%s%s", pageData.Meta.Owner, pageData.Meta.Folder, pageData.Meta.Database))
2254+
if err != nil {
2255+
errorPage(w, r, http.StatusInternalServerError, err.Error())
2256+
return
2257+
}
2258+
} else {
2259+
// Get live node
2260+
_, liveNode, err := com.CheckDBLive(pageData.Meta.Owner, pageData.Meta.Folder, pageData.Meta.Database)
2261+
if err != nil {
2262+
errorPage(w, r, http.StatusInternalServerError, err.Error())
2263+
return
2264+
}
2265+
2266+
// Send the request to our AMQP backend
2267+
var rawResponse []byte
2268+
rawResponse, err = com.MQRequest(com.AmqpChan, liveNode, "tables", pageData.Meta.LoggedInUser, pageData.Meta.Owner, pageData.Meta.Database, nil)
2269+
if err != nil {
2270+
log.Println(err)
2271+
errorPage(w, r, http.StatusInternalServerError, "Error when reading from the database")
2272+
return
2273+
}
2274+
2275+
// Decode the response
2276+
var resp com.LiveDBTablesResponse
2277+
err = json.Unmarshal(rawResponse, &resp)
2278+
if err != nil {
2279+
log.Println(err)
2280+
errorPage(w, r, http.StatusInternalServerError, "Error when reading from the database")
2281+
return
2282+
}
2283+
if resp.Error != "" {
2284+
err = errors.New(resp.Error)
2285+
log.Println(err)
2286+
errorPage(w, r, http.StatusInternalServerError, "Error when reading from the database")
2287+
return
2288+
}
2289+
if resp.Node == "" {
2290+
log.Printf("In webUI (Live) settingsPage(). A node responded, but didn't identify itself.")
2291+
return
2292+
}
2293+
pageData.DB.Info.Tables = resp.Tables
22552294
}
22562295

22572296
// Retrieve the list of branches

0 commit comments

Comments
 (0)