Minor optimization regarding regexp filtering in timelines

master
Thibaut Girka 5 years ago committed by ThibG
parent c49f7d5d16
commit 9d6b46fe34
  1. 21
      app/javascript/flavours/glitch/features/ui/containers/status_list_container.js

@ -6,19 +6,26 @@ import { createSelector } from 'reselect';
import { debounce } from 'lodash'; import { debounce } from 'lodash';
import { me } from 'flavours/glitch/util/initial_state'; import { me } from 'flavours/glitch/util/initial_state';
const makeGetStatusIds = () => createSelector([ const getRegex = createSelector([
(state, { type }) => state.getIn(['settings', type], ImmutableMap()), (state, { type }) => state.getIn(['settings', type, 'regex', 'body']),
(state, { type }) => state.getIn(['timelines', type, 'items'], ImmutableList()), ], (rawRegex) => {
(state) => state.get('statuses'),
], (columnSettings, statusIds, statuses) => {
const rawRegex = columnSettings.getIn(['regex', 'body'], '').trim();
let regex = null; let regex = null;
try { try {
regex = rawRegex && new RegExp(rawRegex, 'i'); regex = rawRegex && new RegExp(rawRegex.trim(), 'i');
} catch (e) { } catch (e) {
// Bad regex, don't affect filters // Bad regex, don't affect filters
} }
return regex;
});
const makeGetStatusIds = () => createSelector([
(state, { type }) => state.getIn(['settings', type], ImmutableMap()),
(state, { type }) => state.getIn(['timelines', type, 'items'], ImmutableList()),
(state) => state.get('statuses'),
getRegex,
], (columnSettings, statusIds, statuses, regex) => {
const rawRegex = columnSettings.getIn(['regex', 'body'], '').trim();
return statusIds.filter(id => { return statusIds.filter(id => {
if (id === null) return true; if (id === null) return true;

Loading…
Cancel
Save