Skip to content

Commit

Permalink
Option to configure number of saved responses to history (#1378)
Browse files Browse the repository at this point in the history
  • Loading branch information
Grimones authored and gschier committed Apr 18, 2019
1 parent 9208505 commit e145ca8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
1 change: 0 additions & 1 deletion packages/insomnia-app/app/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export function getClientString() {
// Global Stuff
export const DB_PERSIST_INTERVAL = 1000 * 60 * 60 * 2; // Compact every couple hour
export const DEBOUNCE_MILLIS = 100;
export const MAX_RESPONSES = 20;
export const REQUEST_TIME_TO_SHOW_COUNTER = 1; // Seconds
export const GA_ID = 'UA-86416787-1';
export const GA_LOCATION = 'https://desktop.insomnia.rest/';
Expand Down
9 changes: 7 additions & 2 deletions packages/insomnia-app/app/models/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import crypto from 'crypto';
import path from 'path';
import zlib from 'zlib';
import mkdirp from 'mkdirp';
import { MAX_RESPONSES } from '../common/constants';
import * as db from '../common/database';
import { getDataDirectory } from '../common/misc';

Expand Down Expand Up @@ -131,13 +130,19 @@ export async function create(patch: Object = {}, maxResponses: number = 20) {

const { parentId } = patch;

const settings = await models.settings.getOrCreate();

// Create request version snapshot
const request = await models.request.getById(parentId);
const requestVersion = request ? await models.requestVersion.create(request) : null;
patch.requestVersionId = requestVersion ? requestVersion._id : null;

// Delete all other responses before creating the new one
const allResponses = await db.findMostRecentlyModified(type, { parentId }, MAX_RESPONSES);
const allResponses = await db.findMostRecentlyModified(
type,
{ parentId },
settings.maxHistoryResponses,
);
const recentIds = allResponses.map(r => r._id);
await db.removeWhere(type, { parentId, _id: { $nin: recentIds } });

Expand Down
2 changes: 2 additions & 0 deletions packages/insomnia-app/app/models/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type BaseSettings = {
autoHideMenuBar: boolean,
theme: string,
maxRedirects: number,
maxHistoryResponses: number,
pluginPath: string,
nunjucksPowerUserMode: boolean,
deviceId: string | null,
Expand Down Expand Up @@ -63,6 +64,7 @@ export function init(): BaseSettings {
httpsProxy: '',
noProxy: '',
maxRedirects: -1,
maxHistoryResponses: 20,
proxyEnabled: false,
timeout: 0,
validateSSL: true,
Expand Down
13 changes: 13 additions & 0 deletions packages/insomnia-app/app/ui/components/settings/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,19 @@ class General extends React.PureComponent<Props, State> {
</label>
</div>

<div className="form-control form-control--outlined">
<label className="inline-block">
Max history responses
<input
type="number"
name="maxHistoryResponses"
min={1}
defaultValue={settings.maxHistoryResponses}
onChange={this._handleUpdateSetting}
/>
</label>
</div>

<div className="form-row">
<div className="form-control form-control--outlined pad-top-sm">
<label>
Expand Down

0 comments on commit e145ca8

Please sign in to comment.