mirror of
https://github.com/Kong/insomnia
synced 2024-11-07 22:30:15 +00:00
Moved sync directory and sync DB buffering
This commit is contained in:
parent
f1dd218944
commit
d3c5510f67
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 39 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
@ -1,6 +1,6 @@
|
||||
import {parse as urlParse} from 'url';
|
||||
import {isDevelopment} from './appInfo';
|
||||
import * as session from './sync/session';
|
||||
import * as session from '../sync/session';
|
||||
import * as appInfo from './appInfo';
|
||||
|
||||
let commandListeners = [];
|
||||
|
@ -1,5 +1,6 @@
|
||||
import uuid from 'node-uuid';
|
||||
import {parse as urlParse, format as urlFormat} from 'url';
|
||||
import {DEBOUNCE_MILLIS} from "./constants";
|
||||
|
||||
export function getBasicAuthHeader (username, password) {
|
||||
const name = 'Authorization';
|
||||
@ -98,3 +99,13 @@ export function delay (milliseconds) {
|
||||
export function removeVowels (str) {
|
||||
return str.replace(/[aeiouyAEIOUY]/g, '');
|
||||
}
|
||||
|
||||
export function debounce (callback, millis = DEBOUNCE_MILLIS) {
|
||||
let timeout = null;
|
||||
return function () {
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(() => {
|
||||
callback.apply(null, arguments)
|
||||
}, millis);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import * as db from '../database';
|
||||
import * as fetch from '../fetch';
|
||||
import * as db from '../backend/database';
|
||||
import * as fetch from '../backend/fetch';
|
||||
import * as crypt from './crypt';
|
||||
import * as session from './session';
|
||||
import * as store from './storage';
|
||||
@ -136,6 +136,7 @@ export async function pushActiveDirtyResources (resourceGroupId = null) {
|
||||
}
|
||||
|
||||
// Resolve conflicts
|
||||
db.bufferChanges();
|
||||
for (const serverResource of conflicts) {
|
||||
const localResource = await store.getResourceByDocId(
|
||||
serverResource.id,
|
||||
@ -169,6 +170,7 @@ export async function pushActiveDirtyResources (resourceGroupId = null) {
|
||||
}
|
||||
}
|
||||
}
|
||||
db.flushChanges();
|
||||
}
|
||||
|
||||
export async function pull (resourceGroupId = null, createMissingResources = true) {
|
||||
@ -226,7 +228,8 @@ export async function pull (resourceGroupId = null, createMissingResources = tru
|
||||
// Insert all the created docs to the DB //
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
|
||||
|
||||
await createdResources.map(async serverResource => {
|
||||
db.bufferChanges();
|
||||
for (const serverResource of createdResources) {
|
||||
let doc;
|
||||
|
||||
try {
|
||||
@ -252,7 +255,8 @@ export async function pull (resourceGroupId = null, createMissingResources = tru
|
||||
// it's very possible that the client already had that document locally.
|
||||
// This might happen, for example, if the user logs out and back in again.
|
||||
await db.upsert(doc, true);
|
||||
});
|
||||
}
|
||||
db.flushChanges();
|
||||
|
||||
if (createdResources.length) {
|
||||
logger.debug(`Pull created ${createdResources.length} resources`);
|
||||
@ -262,7 +266,8 @@ export async function pull (resourceGroupId = null, createMissingResources = tru
|
||||
// Save all the updated docs to the DB //
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
|
||||
|
||||
await updatedResources.map(async serverResource => {
|
||||
db.bufferChanges();
|
||||
for (const serverResource of updatedResources) {
|
||||
try {
|
||||
const {resourceGroupId, encContent} = serverResource;
|
||||
const doc = await _decryptDoc(resourceGroupId, encContent);
|
||||
@ -279,7 +284,8 @@ export async function pull (resourceGroupId = null, createMissingResources = tru
|
||||
} catch (e) {
|
||||
logger.warn('Failed to decode updated resource', e, serverResource);
|
||||
}
|
||||
});
|
||||
}
|
||||
db.flushChanges();
|
||||
|
||||
if (updatedResources.length) {
|
||||
logger.debug(`Pull updated ${updatedResources.length} resources`);
|
||||
@ -289,6 +295,7 @@ export async function pull (resourceGroupId = null, createMissingResources = tru
|
||||
// Remove all the docs that need removing //
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
|
||||
|
||||
db.bufferChanges();
|
||||
for (const id of idsToRemove) {
|
||||
const resource = await store.getResourceByDocId(id);
|
||||
if (!resource) {
|
||||
@ -306,6 +313,7 @@ export async function pull (resourceGroupId = null, createMissingResources = tru
|
||||
// Remove from DB
|
||||
await db.remove(doc, true);
|
||||
}
|
||||
db.flushChanges();
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
|
||||
// Push all the docs that need pushing //
|
@ -1,8 +1,7 @@
|
||||
import srp from 'srp';
|
||||
import * as crypt from './crypt';
|
||||
import * as util from '../fetch';
|
||||
import * as ganalytics from '../ganalytics';
|
||||
import {trackEvent} from '../ganalytics';
|
||||
import * as util from '../backend/fetch';
|
||||
import * as analytics from '../backend/ganalytics';
|
||||
|
||||
const NO_SESSION = '__NO_SESSION__';
|
||||
|
||||
@ -47,7 +46,7 @@ export async function signup (firstName, lastName, rawEmail, rawPassphrase) {
|
||||
|
||||
const response = await util.post('/auth/signup', account);
|
||||
|
||||
trackEvent('Session', 'Signup');
|
||||
analytics.trackEvent('Session', 'Signup');
|
||||
|
||||
return response;
|
||||
}
|
||||
@ -140,9 +139,8 @@ export async function login (rawEmail, rawPassphrase) {
|
||||
);
|
||||
|
||||
// Set the ID for Google Analytics
|
||||
ganalytics.setAccountId(accountId);
|
||||
|
||||
trackEvent('Session', 'Login');
|
||||
analytics.setAccountId(accountId);
|
||||
analytics.trackEvent('Session', 'Login');
|
||||
}
|
||||
|
||||
export async function subscribe (tokenId, planId) {
|
||||
@ -151,7 +149,7 @@ export async function subscribe (tokenId, planId) {
|
||||
quantity: 1,
|
||||
plan: planId,
|
||||
});
|
||||
trackEvent('Session', 'Subscribe', planId, 1);
|
||||
analytics.trackEvent('Session', 'Subscribe', planId, 1);
|
||||
return response;
|
||||
}
|
||||
|
||||
@ -261,7 +259,7 @@ export function isLoggedIn () {
|
||||
export async function logout () {
|
||||
await util.post('/auth/logout');
|
||||
unsetSessionData();
|
||||
trackEvent('Session', 'Logout');
|
||||
analytics.trackEvent('Session', 'Logout');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -269,7 +267,7 @@ export async function logout () {
|
||||
*/
|
||||
export async function cancelAccount () {
|
||||
await util.del('/api/billing/subscriptions');
|
||||
trackEvent('Session', 'Cancel Account');
|
||||
analytics.trackEvent('Session', 'Cancel Account');
|
||||
}
|
||||
|
||||
/**
|
@ -2,7 +2,7 @@ import electron from 'electron';
|
||||
import NeDB from 'nedb';
|
||||
import fsPath from 'path';
|
||||
import crypto from 'crypto';
|
||||
import * as util from '../util';
|
||||
import * as util from '../backend/util';
|
||||
|
||||
const TYPE_RESOURCE = 'Resource';
|
||||
const TYPE_CONFIG = 'Config';
|
@ -12,7 +12,7 @@ import {
|
||||
getContentTypeFromHeaders
|
||||
} from '../../backend/contentTypes';
|
||||
import {MOD_SYM} from '../../backend/constants';
|
||||
import {debounce} from '../lib/debounce';
|
||||
import {debounce} from '../../backend/util';
|
||||
|
||||
class RequestPane extends Component {
|
||||
render () {
|
||||
|
@ -56,7 +56,7 @@ class RequestUrlBar extends Component {
|
||||
<li key={method}>
|
||||
<button onClick={e => {
|
||||
onMethodChange(method);
|
||||
trackEvent('Changed Method', {method});
|
||||
trackEvent('Request', 'Method Change', {method});
|
||||
}}>
|
||||
<div className={classnames('dropdown__inner', `method-${method}`)}>
|
||||
<span className="dropdown__text">
|
||||
|
@ -1,8 +1,8 @@
|
||||
import React, {Component, PropTypes} from 'react';
|
||||
import SyncModal from './modals/SyncModal';
|
||||
import {showModal} from './modals/index';
|
||||
import * as syncStorage from '../../backend/sync/storage';
|
||||
import * as session from '../../backend/sync/session';
|
||||
import * as syncStorage from '../../sync/storage';
|
||||
import * as session from '../../sync/session';
|
||||
import SignupModal from './modals/SignupModal';
|
||||
|
||||
const STATE_OK = 'synced';
|
||||
|
@ -44,7 +44,7 @@ class Modal extends Component {
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
this._node.focus();
|
||||
this._node && this._node.focus();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -4,10 +4,10 @@ import Modal from '../base/Modal';
|
||||
import ModalBody from '../base/ModalBody';
|
||||
import ModalHeader from '../base/ModalHeader';
|
||||
import ModalFooter from '../base/ModalFooter';
|
||||
import * as session from '../../../backend/sync/session';
|
||||
import * as session from '../../../sync/session';
|
||||
import {showModal} from './index';
|
||||
import SignupModal from './SignupModal';
|
||||
import * as sync from '../../../backend/sync';
|
||||
import * as sync from '../../../sync';
|
||||
import {trackEvent} from '../../../backend/ganalytics';
|
||||
|
||||
class LoginModal extends Component {
|
||||
|
@ -5,7 +5,7 @@ import Modal from '../base/Modal';
|
||||
import ModalBody from '../base/ModalBody';
|
||||
import ModalHeader from '../base/ModalHeader';
|
||||
import ModalFooter from '../base/ModalFooter';
|
||||
import * as session from '../../../backend/sync/session';
|
||||
import * as session from '../../../sync/session';
|
||||
|
||||
const MONTHS = [
|
||||
{name: 'January', value: '01'},
|
||||
|
@ -18,10 +18,10 @@ import {
|
||||
getAppVersion,
|
||||
getAppLongName
|
||||
} from '../../../backend/appInfo';
|
||||
import * as session from '../../../backend/sync/session';
|
||||
import * as session from '../../../sync/session';
|
||||
import {showModal} from './index';
|
||||
import SignupModal from './SignupModal';
|
||||
import * as sync from '../../../backend/sync/index';
|
||||
import * as sync from '../../../sync';
|
||||
|
||||
|
||||
class SettingsTabs extends Component {
|
||||
|
@ -4,10 +4,10 @@ import Modal from '../base/Modal';
|
||||
import ModalBody from '../base/ModalBody';
|
||||
import ModalHeader from '../base/ModalHeader';
|
||||
import ModalFooter from '../base/ModalFooter';
|
||||
import * as session from '../../../backend/sync/session';
|
||||
import * as session from '../../../sync/session';
|
||||
import {showModal} from './index';
|
||||
import LoginModal from './LoginModal';
|
||||
import * as sync from '../../../backend/sync';
|
||||
import * as sync from '../../../sync';
|
||||
import {trackEvent} from '../../../backend/ganalytics';
|
||||
|
||||
class SignupModal extends Component {
|
||||
|
@ -1,15 +1,14 @@
|
||||
import React, {Component} from 'react';
|
||||
import classnames from 'classnames';
|
||||
import GravatarImg from '../GravatarImg';
|
||||
import Modal from '../base/Modal';
|
||||
import PromptButton from '../base/PromptButton';
|
||||
import ModalBody from '../base/ModalBody';
|
||||
import ModalHeader from '../base/ModalHeader';
|
||||
import ModalFooter from '../base/ModalFooter';
|
||||
import {Tab, Tabs, TabList, TabPanel} from 'react-tabs';
|
||||
import * as session from '../../../backend/sync/session';
|
||||
import * as syncStorage from '../../../backend/sync/storage';
|
||||
import * as sync from '../../../backend/sync';
|
||||
import * as session from '../../../sync/session';
|
||||
import * as syncStorage from '../../../sync/storage';
|
||||
import * as sync from '../../../sync';
|
||||
import * as db from '../../../backend/database';
|
||||
import {trackEvent} from '../../../backend/ganalytics';
|
||||
|
||||
|
@ -10,11 +10,11 @@ import './css/index.less';
|
||||
import './css/lib/chrome/platform_app.css';
|
||||
import {initStore} from './redux/initstore';
|
||||
import {initDB} from '../backend/database';
|
||||
import {initSync} from '../backend/sync';
|
||||
import {initSync} from '../sync';
|
||||
import {getAppVersion} from '../backend/appInfo';
|
||||
import {initLegacyAnalytics} from '../backend/analytics';
|
||||
import {initAnalytics} from '../backend/ganalytics';
|
||||
import * as session from '../backend/sync/session';
|
||||
import * as session from '../sync/session';
|
||||
|
||||
// Global CSS
|
||||
|
||||
|
@ -1,11 +0,0 @@
|
||||
import {DEBOUNCE_MILLIS} from '../../backend/constants';
|
||||
|
||||
export function debounce (callback, millis = DEBOUNCE_MILLIS) {
|
||||
let timeout = null;
|
||||
return function () {
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(() => {
|
||||
callback.apply(null, arguments)
|
||||
}, millis);
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ echo "-- COPYING REMAINING FILES --"
|
||||
cp app/package.json "$BUILD_DIR"
|
||||
|
||||
# Copy some things
|
||||
cp -r app/external assets/* app/main.js "$BUILD_DIR/"
|
||||
cp -r app/external app/assets/* app/main.js "$BUILD_DIR/"
|
||||
|
||||
echo "-- INSTALLING PACKAGES --"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user