Skip to content

Commit 0f5f2b5

Browse files
author
Auke Booij
authored
Merge branch 'master' into 4547-introspection-reuse-variables
2 parents 140e89b + 6ffb29b commit 0f5f2b5

File tree

10 files changed

+58
-49
lines changed

10 files changed

+58
-49
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Read more about the session argument for computed fields in the [docs](https://h
3737
(Add entries here in the order of: server, console, cli, docs, others)
3838

3939
- server: avoid an error when calling a cached introspection query (fix #4547)
40+
- console: avoid count queries for large tables (#4692)
4041
- console: add read replica support section to pro popup (#4118)
4142
- cli: list all avialable commands in root command help (fix #4623)
4243

cli/commands/docs.go

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ import (
44
"bytes"
55
"fmt"
66
"io"
7-
"io/ioutil"
87
"os"
98
"path/filepath"
109
"sort"
1110
"strings"
1211

1312
"github.com/hasura/graphql-engine/cli"
14-
"github.com/markbates/pkger"
1513
"github.com/pkg/errors"
1614
"github.com/spf13/cobra"
1715
"github.com/spf13/cobra/doc"
@@ -105,26 +103,12 @@ func genReSTCustom(cmd *cobra.Command, w io.Writer, titlePrefix string, linkHand
105103
buf := new(bytes.Buffer)
106104
name := cmd.CommandPath()
107105
ref := strings.Replace(name, " ", "_", -1)
108-
cliDocPath := "manifests/docs/" + ref + ".rst"
109106
short := cmd.Short
110107
long := cmd.Long
111108
if len(long) == 0 {
112109
long = short
113110
}
114-
file, err := pkger.Open(cliDocPath)
115-
if err != nil {
116-
return err
117-
}
118-
fileInfo, err := ioutil.ReadAll(file)
119-
if err != nil {
120-
return err
121-
}
122-
var info string
123-
if err != nil || string(fileInfo) == "" {
124-
info = short
125-
} else {
126-
info = string(fileInfo)
127-
}
111+
info := short
128112

129113
buf.WriteString(".. _" + ref + ":\n\n")
130114

@@ -184,7 +168,7 @@ func genReSTCustom(cmd *cobra.Command, w io.Writer, titlePrefix string, linkHand
184168
if !cmd.DisableAutoGenTag {
185169
buf.WriteString("*Auto generated by spf13/cobra*\n")
186170
}
187-
_, err = buf.WriteTo(w)
171+
_, err := buf.WriteTo(w)
188172
return err
189173
}
190174

console/src/components/Services/Data/DataState.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const defaultViewState = {
2222
manualTriggers: [],
2323
triggeredRow: -1,
2424
triggeredFunction: null,
25+
estimatedCount: 0,
26+
isCountEstimated: 0,
2527
};
2628

2729
const defaultPermissionsState = {

console/src/components/Services/Data/TableBrowseRows/FilterQuery.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import Button from '../../../Common/Button/Button';
2727
import ReloadEnumValuesButton from '../Common/Components/ReloadEnumValuesButton';
2828
import styles from '../../../Common/FilterQuery/FilterQuery.scss';
2929
import { getPersistedPageSize } from './localStorageUtils';
30+
import { isEmpty } from '../../../Common/utils/jsUtils';
3031

3132
const history = createHistory();
3233

@@ -205,7 +206,7 @@ class FilterQuery extends Component {
205206
componentDidMount() {
206207
const { dispatch, tableSchema, curQuery } = this.props;
207208
const limit = getPersistedPageSize();
208-
if (!this.props.urlQuery) {
209+
if (isEmpty(this.props.urlQuery)) {
209210
dispatch(setDefaultQuery({ ...curQuery, limit }));
210211
return;
211212
}

console/src/components/Services/Data/TableBrowseRows/ViewActions.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
getRunSqlQuery,
1818
} from '../../../Common/utils/v1QueryUtils';
1919
import { generateTableDef } from '../../../Common/utils/pgUtils';
20+
import { COUNT_LIMIT } from '../constants';
2021

2122
/* ****************** View actions *************/
2223
const V_SET_DEFAULTS = 'ViewTable/V_SET_DEFAULTS';
@@ -96,7 +97,7 @@ const vMakeRowsRequest = () => {
9697
dispatch({
9798
type: V_REQUEST_SUCCESS,
9899
data: data[0],
99-
estimatedCount: data[1].result[1],
100+
estimatedCount: parseInt(data[1].result[1][0], 10),
100101
}),
101102
dispatch({ type: V_REQUEST_PROGRESS, data: false }),
102103
]);
@@ -157,9 +158,19 @@ const vMakeCountRequest = () => {
157158
};
158159
};
159160

160-
const vMakeTableRequests = () => dispatch => {
161-
dispatch(vMakeRowsRequest());
162-
dispatch(vMakeCountRequest());
161+
const vMakeTableRequests = () => (dispatch, getState) => {
162+
dispatch(vMakeRowsRequest()).then(() => {
163+
const { estimatedCount } = getState().tables.view;
164+
if (estimatedCount > COUNT_LIMIT) {
165+
dispatch({
166+
type: V_COUNT_REQUEST_SUCCESS,
167+
count: estimatedCount,
168+
isEstimated: true,
169+
});
170+
} else {
171+
dispatch(vMakeCountRequest());
172+
}
173+
});
163174
};
164175

165176
const fetchManualTriggers = tableName => {
@@ -572,7 +583,11 @@ const viewReducer = (tableName, currentSchema, schemas, viewState, action) => {
572583
case V_REQUEST_PROGRESS:
573584
return { ...viewState, isProgressing: action.data };
574585
case V_COUNT_REQUEST_SUCCESS:
575-
return { ...viewState, count: action.count };
586+
return {
587+
...viewState,
588+
count: action.count,
589+
isCountEstimated: action.isEstimated === true,
590+
};
576591
case V_EXPAND_ROW:
577592
return {
578593
...viewState,

console/src/components/Services/Data/TableBrowseRows/ViewTable.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class ViewTable extends Component {
110110
triggeredFunction,
111111
location,
112112
estimatedCount,
113+
isCountEstimated,
113114
} = this.props;
114115

115116
// check if table exists
@@ -161,7 +162,8 @@ class ViewTable extends Component {
161162
// Choose the right nav bar header thing
162163
const header = (
163164
<TableHeader
164-
count={count}
165+
count={isCountEstimated ? estimatedCount : count}
166+
isCountEstimated={isCountEstimated}
165167
dispatch={dispatch}
166168
table={tableSchema}
167169
tabName="browse"

console/src/components/Services/Data/TableCommon/TableHeader.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { Link } from 'react-router';
33
import Helmet from 'react-helmet';
44
import { changeTableName } from '../TableModify/ModifyActions';
5-
import { capitalize } from '../../../Common/utils/jsUtils';
5+
import { capitalize, exists } from '../../../Common/utils/jsUtils';
66
import EditableHeading from '../../../Common/EditableHeading/EditableHeading';
77
import BreadCrumb from '../../../Common/Layout/BreadCrumb/BreadCrumb';
88
import { tabNameMap } from '../utils';
@@ -26,6 +26,7 @@ import { getReadableNumber } from '../../../Common/utils/jsUtils';
2626
const TableHeader = ({
2727
tabName,
2828
count,
29+
isCountEstimated,
2930
table,
3031
migrationMode,
3132
readOnlyMode,
@@ -38,8 +39,11 @@ const TableHeader = ({
3839
const isTable = checkIfTable(table);
3940

4041
let countDisplay = '';
41-
if (!(count === null || count === undefined)) {
42-
countDisplay = '(' + getReadableNumber(count) + ')';
42+
// if (exists(count)) {
43+
// countDisplay = `(${isCountEstimated ? '~' : '' }${getReadableNumber(count)})`;
44+
// }
45+
if (exists(count) && !isCountEstimated) {
46+
countDisplay = `(${getReadableNumber(count)})`;
4347
}
4448
const activeTab = tabNameMap[tabName];
4549

console/src/components/Services/Data/constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export const Integers = [
3838
'bigint',
3939
];
4040

41+
export const COUNT_LIMIT = 100000;
42+
4143
export const Reals = ['float4', 'float8', 'numeric'];
4244

4345
export const Numerics = [...Integers, ...Reals];

docs/_theme/djangodocs/basic/layout.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,13 @@ <h3>{{ _('Navigation') }}</h3>
138138
{%- block scripts %}
139139
{{- script() }}
140140
{%- endblock %}
141+
<!-- Google Tag Manager -->
142+
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
143+
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
144+
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
145+
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
146+
})(window,document,'script','dataLayer','GTM-PF5MQ2Z');</script>
147+
<!-- End Google Tag Manager -->
141148
{%- if use_opensearch %}
142149
<link rel="search" type="application/opensearchdescription+xml"
143150
title="{% trans docstitle=docstitle|e %}Search within {{ docstitle }}{% endtrans %}"
@@ -174,6 +181,10 @@ <h3>{{ _('Navigation') }}</h3>
174181
{%- block content %}
175182
{%- block sidebar1 %} {# possible location for sidebar #} {% endblock %}
176183

184+
<!-- Google Tag Manager (noscript) -->
185+
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-PF5MQ2Z"
186+
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
187+
<!-- End Google Tag Manager (noscript) -->
177188
<div class="document">
178189
{%- block document %}
179190
<div class="documentwrapper">

docs/_theme/djangodocs/layout.html

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -168,17 +168,6 @@
168168
{% block sidebar2 %}{% endblock %}
169169
{% block footer %}
170170

171-
<!-- GA -->
172-
<script>
173-
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
174-
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
175-
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
176-
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
177-
178-
ga('create', 'UA-59768903-1', 'auto');
179-
ga('send', 'pageview');
180-
</script>
181-
182171
<!-- intercom -->
183172
<script>
184173
window.intercomSettings = {
@@ -259,16 +248,14 @@
259248

260249
// Track GA event
261250
const trackga = function ( category, action, label, value ) {
262-
// If ga is available
263-
if ( ga ) {
264-
ga('send', {
265-
hitType: 'event',
266-
eventCategory: category,
267-
eventAction: action,
268-
eventLabel: label,
269-
eventValue: value
270-
});
271-
}
251+
window.dataLayer = window.dataLayer || [];
252+
window.dataLayer.push({
253+
event: 'Click Events',
254+
category: category,
255+
action: action,
256+
label: label,
257+
value: value
258+
})
272259
};
273260
</script>
274261

0 commit comments

Comments
 (0)