Skip to content
Snippets Groups Projects
Commit ca5b09f8 authored by Cam Saül's avatar Cam Saül
Browse files

100x faster query builder & cards :unamused: #1726

parent fdd736b3
No related branches found
No related tags found
No related merge requests found
......@@ -532,6 +532,13 @@ CardControllers.controller('CardDetail', [
tables = null;
tableMetadata = null;
let db = _.findWhere(databases, { id: databaseId });
if (db && db.tables) {
tables = db.tabels;
renderAll();
return;
}
// get tables for db
Metabase.db_tables({
'dbId': databaseId
......@@ -891,19 +898,9 @@ CardControllers.controller('CardDetail', [
}
});
// TODO: while we wait for the databases list we should put something on screen
// grab our database list, then handle the rest
async function loadDatabasesAndTables() {
let dbs = await Metabase.db_list().$promise;
return await * dbs.map(async function(db) {
db.tables = await Metabase.db_tables({ dbId: db.id }).$promise;
return db;
});
}
async function init() {
try {
databases = await loadDatabasesAndTables();
databases = await Metabase.db_list_with_tables().$promise;
if (databases.length < 1) {
// TODO: some indication that setting up a db is required
......
......@@ -26,6 +26,12 @@ export default class DataReferenceMain extends Component {
databases = this.props.databases.map((database) => {
var dbTables = this.state.databases[database.id];
if (dbTables === undefined) {
if (database.tables) {
this.state.databases[database.id] = database.tables;
this.setState({ databases: this.state.databases });
return;
}
this.state.databases[database.id] = null; // null indicates loading
this.props.Metabase.db_tables({
'dbId': database.id
......
......@@ -413,6 +413,14 @@ CoreServices.factory('Metabase', ['$resource', '$cookies', 'MetabaseCore', funct
method: 'GET',
isArray: true
},
db_list_with_tables: {
method: 'GET',
url: '/api/database/',
params: {
include_tables: 'true'
},
isArray: true
},
db_create: {
url: '/api/database/',
method: 'POST'
......
......@@ -51,8 +51,13 @@
(defendpoint GET "/"
"Fetch all `Databases`."
[]
(sel :many Database (k/order :name)))
[include_tables]
(let [dbs (sel :many Database (k/order :name))]
(if-not include_tables
dbs
(let [db-id->tables (group-by :db_id (sel :many Table, :active true))]
(for [db dbs]
(assoc db :tables (sort-by :name (get db-id->tables (:id db) []))))))))
(defendpoint POST "/"
"Add a new `Database`."
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment