Skip to content

Commit

Permalink
Add storage size information and more timings (#1129)
Browse files Browse the repository at this point in the history
  • Loading branch information
borisyankov authored Sep 6, 2017
1 parent 00eec20 commit f4bb919
Show file tree
Hide file tree
Showing 15 changed files with 153 additions and 30 deletions.
33 changes: 33 additions & 0 deletions src/diagnostics/DiagnosticsScreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* @flow */
import React, { PureComponent } from 'react';
import { StyleSheet, View, ScrollView } from 'react-native';
import { connect } from 'react-redux';

import boundActions from '../boundActions';
import { Screen } from '../common';
import OptionButton from '../settings/OptionButton';

const styles = StyleSheet.create({
divider: {
height: 16,
},
});

class DiagnosticsScreen extends PureComponent {
render() {
const { actions } = this.props;
return (
<Screen title="Diagnostics">
<ScrollView>
<OptionButton label="Variables" onPress={actions.navigateToVariables} />
<View style={styles.divider} />
<OptionButton label="Timing" onPress={actions.navigateToTiming} />
<View style={styles.divider} />
<OptionButton label="Storage" onPress={actions.navigateToStorage} />
</ScrollView>
</Screen>
);
}
}

export default connect(null, boundActions)(DiagnosticsScreen);
File renamed without changes.
40 changes: 40 additions & 0 deletions src/diagnostics/SizeItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* @flow */
import React, { PureComponent } from 'react';
import { StyleSheet, View } from 'react-native';

import { RawLabel } from '../common';

const styles = StyleSheet.create({
item: {
flexDirection: 'row',
justifyContent: 'space-between',
padding: 8,
borderBottomWidth: 1,
borderColor: 'rgba(127, 127, 127, 0.25)',
},
key: {},
size: {
fontWeight: 'bold',
},
});

export default class SizeItem extends PureComponent {
props: {
text: string,
size: number,
};

render() {
const { text, size } = this.props;

return (
<View style={styles.item}>
<RawLabel style={styles.key} text={text} />
<RawLabel
style={styles.size}
text={size.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')}
/>
</View>
);
}
}
36 changes: 36 additions & 0 deletions src/diagnostics/StorageScreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* @flow */
import React, { PureComponent } from 'react';
import { FlatList } from 'react-native';
import { connect } from 'react-redux';

import { Screen } from '../common';
import SizeItem from './SizeItem';

const calculateKeyStorageSizes = obj =>
Object.keys(obj)
.map(key => ({
key,
size: JSON.stringify(obj[key]).length * 2,
}))
.sort((a, b) => b.size - a.size);

class StorageScreen extends PureComponent {
render() {
const { state } = this.props;
const storageSizes = calculateKeyStorageSizes(state);

return (
<Screen title="Storage">
<FlatList
data={storageSizes}
keyExtractor={item => item.key}
renderItem={({ item }) => <SizeItem text={item.key} size={item.size} />}
/>
</Screen>
);
}
}

export default connect(state => ({
state,
}))(StorageScreen);
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class TimingScreen extends PureComponent {
<Screen title="Timing">
<FlatList
data={timing.log}
keyExtractor={item => item}
keyExtractor={item => item.text}
renderItem={({ item }) => <TimeItem text={item.text} start={item.start} end={item.end} />}
/>
</Screen>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import config from '../config';
import { Screen } from '../common';
import InfoItem from './InfoItem';

export default class DiagnosticsScreen extends PureComponent {
export default class VariablesScreen extends PureComponent {
render() {
return (
<Screen title="Diagnostics">
<Screen title="Variables">
<ScrollView>
<InfoItem label="enableReduxLogging" value={config.enableReduxLogging} />
<InfoItem label="enableSentry" value={config.enableSentry} />
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/translations/messages_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,7 @@
"Toggle compose tools": "Toggle compose tools",
"Terms of service": "Terms of service",
"Privacy policy": "Privacy policy",
"Timing": "Timing"
"Timing": "Timing",
"Variables": "Variables",
"Storage": "Storage"
}
4 changes: 2 additions & 2 deletions src/main/MainTabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { BRAND_COLOR } from '../styles';
import UnreadStreamsContainer from '../unread/UnreadStreamsContainer';
import StreamTabs from '../nav/StreamTabs';
import ConversationsContainer from '../conversations/ConversationsContainer';
import SettingsContainer from '../settings/SettingsContainer';
import SettingsCard from '../settings/SettingsCard';
import { IconHome, IconStream, IconPrivateChat, IconSettings } from '../common/Icons';

export default TabNavigator(
Expand All @@ -33,7 +33,7 @@ export default TabNavigator(
},
},
settings: {
screen: SettingsContainer,
screen: SettingsCard,
navigationOptions: {
tabBarLabel: 'Settings',
tabBarIcon: ({ tintColor }) => <IconSettings size={24} color={tintColor} />,
Expand Down
8 changes: 6 additions & 2 deletions src/nav/AppNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import ChatScreen from '../chat/ChatScreen';
import LoadingScreen from '../start/LoadingScreen';
import SettingsScreen from '../settings/SettingsScreen';
import LanguageScreen from '../settings/LanguageScreen';
import DiagnosticsScreen from '../settings/DiagnosticsScreen';
import TimingScreen from '../settings/TimingScreen';
import DiagnosticsScreen from '../diagnostics/DiagnosticsScreen';
import VariablesScreen from '../diagnostics/VariablesScreen';
import TimingScreen from '../diagnostics/TimingScreen';
import StorageScreen from '../diagnostics/StorageScreen';
import LightboxScreen from '../lightbox/LightboxScreen';
import GroupScreen from '../group/GroupScreen';

Expand All @@ -39,7 +41,9 @@ export default StackNavigator(
lightbox: { screen: LightboxScreen },
group: { screen: GroupScreen },
diagnostics: { screen: DiagnosticsScreen },
variables: { screen: VariablesScreen },
timing: { screen: TimingScreen },
storage: { screen: StorageScreen },
},
{
initialRouteName: 'main',
Expand Down
5 changes: 5 additions & 0 deletions src/nav/navActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,9 @@ export const navigateToCreateGroup = (): Action =>
export const navigateToDiagnostics = (): Action =>
NavigationActions.navigate({ routeName: 'diagnostics' });

export const navigateToVariables = (): Action =>
NavigationActions.navigate({ routeName: 'variables' });

export const navigateToTiming = (): Action => NavigationActions.navigate({ routeName: 'timing' });

export const navigateToStorage = (): Action => NavigationActions.navigate({ routeName: 'storage' });
8 changes: 8 additions & 0 deletions src/realm/realmActions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* @flow */
import type { GetState, Dispatch, Action } from '../types';
import config from '../config';
import timing from '../utils/timing';
import { allPrivateNarrow } from '../utils/narrow';
import { tryUntilSuccessful } from '../utils/async';
import { getMessages, getStreams, getUsers, registerForEvents } from '../api';
Expand Down Expand Up @@ -52,11 +53,14 @@ export const fetchEssentialInitialData = (): Action => async (
const narrow = getActiveNarrow(getState());
const halfCount = Math.trunc(config.messagesPerRequest / 2);

timing.start('Essential server data');
const [initData, messages] = await Promise.all([
await tryUntilSuccessful(() => registerForEvents(auth)),
await tryUntilSuccessful(() => getMessages(auth, 0, halfCount, halfCount, narrow, true)),
]);

timing.end('Essential server data');

dispatch(realmInit(initData));
dispatch(messageFetchSuccess(messages, narrow, 0, halfCount, halfCount, true));
dispatch(initialFetchComplete());
Expand All @@ -70,13 +74,17 @@ export const fetchRestOfInitialData = (): Action => async (
) => {
const auth = getAuth(getState());
const pushToken = getPushToken(getState());

timing.start('Rest of server data');
const [messages, streams, users] = await Promise.all([
await tryUntilSuccessful(() =>
getMessages(auth, Number.MAX_SAFE_INTEGER, 100, 0, allPrivateNarrow),
),
await tryUntilSuccessful(() => getStreams(auth)),
await tryUntilSuccessful(() => getUsers(auth)),
]);

timing.end('Rest of server data');
dispatch(messageFetchSuccess(messages, allPrivateNarrow, 0, 0, 0, true));
dispatch(initStreams(streams));
dispatch(initUsers(users));
Expand Down
2 changes: 0 additions & 2 deletions src/settings/SettingsCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ export default class SettingsCard extends PureComponent {
<OptionButton label="Language" onPress={actions.navigateToLanguage} />
<View style={styles.divider} />
<OptionButton label="Diagnostics" onPress={actions.navigateToDiagnostics} />
<View style={styles.divider} />
<OptionButton label="Timing" onPress={actions.navigateToTiming} />
<View style={styles.padding}>
<WebLink label="Terms of service" href="/terms/" />
<WebLink label="Privacy policy" href="/privacy/" />
Expand Down
16 changes: 0 additions & 16 deletions src/settings/SettingsContainer.js

This file was deleted.

21 changes: 17 additions & 4 deletions src/settings/SettingsScreen.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
/* @flow */
/* TODO flow */
import React, { PureComponent } from 'react';
import { connect } from 'react-redux';

import boundActions from '../boundActions';
import { getAuth } from '../selectors';
import { Screen } from '../common';
import SettingsContainer from './SettingsContainer';
import SettingsCard from './SettingsCard';

export default class SettingsScreen extends PureComponent {
class SettingsScreen extends PureComponent {
render() {
return (
<Screen title="Settings">
<SettingsContainer />
<SettingsCard {...this.props} />
</Screen>
);
}
}

export default connect(
state => ({
offlineNotification: state.settings.offlineNotification,
onlineNotification: state.settings.onlineNotification,
theme: state.settings.theme,
auth: getAuth(state),
}),
boundActions,
)(SettingsScreen);

0 comments on commit f4bb919

Please sign in to comment.