<commit_before>'use strict';

const _ = require('lodash');

const keys = {
  CONFIGURATION: 'configuration',
};

const getStore = () => {
  return strapi.store({
    environment: '',
    type: 'plugin',
    name: 'content_manager',
  });
};

/** Model configuration */
const EMPTY_CONFIG = {
  settings: {},
  metadatas: {},
  layouts: {},
};

const configurationKey = key => `${keys.CONFIGURATION}_${key}`;

const getModelConfiguration = async key => {
  const config = await getStore().get({ key: configurationKey(key) });
  return _.merge({}, EMPTY_CONFIG, config);
};

const setModelConfiguration = async (key, value) => {
  const config = (await getStore().get({ key: configurationKey(key) })) || {};

  Object.keys(value).forEach(key => {
    if (value[key] !== null && value[key] !== undefined) {
      _.set(config, key, value[key]);
    }
  });

  return getStore().set({
    key: configurationKey(key),
    value: config,
  });
};

const deleteKey = key => {
  return strapi
    .query('core_store')
    .delete({ key: `plugin_content_manager_configuration_${key}` });
};

function findByKeyQuery({ model }, key) {
  if (model.orm === 'mongoose') {
    return model
      .find({
        key: { $regex: `${key}.*` },
      })
      .then(results => results.map(({ value }) => JSON.parse(value)));<commit_msg>Suppress rewrite config in db without changes<commit_after>'use strict';

const _ = require('lodash');

const keys = {
  CONFIGURATION: 'configuration',
};

const getStore = () => {
  return strapi.store({
    environment: '',
    type: 'plugin',
    name: 'content_manager',
  });
};

/** Model configuration */
const EMPTY_CONFIG = {
  settings: {},
  metadatas: {},
  layouts: {},
};

const configurationKey = key => `${keys.CONFIGURATION}_${key}`;

const getModelConfiguration = async key => {
  const config = await getStore().get({ key: configurationKey(key) });
  return _.merge({}, EMPTY_CONFIG, config);
};

const setModelConfiguration = async (key, value) => {
  const storedConfig = (await getStore().get({ key: configurationKey(key) })) || {};
  const currentConfig = { ...storedConfig };
  Object.keys(value).forEach(key => {
    if (value[key] !== null && value[key] !== undefined) {
      _.set(currentConfig, key, value[key]);
    }
  });

  if(JSON.stringify(currentConfig) != JSON.stringify(storedConfig)) {
    return getStore().set({
      key: configurationKey(key),
      value: currentConfig,
    });
  }
 
};

const deleteKey = key => {
  return strapi
    .query('core_store')
    .delete({ key: `plugin_content_manager_configuration_${key}` });
};

function findByKeyQuery({ model }, key) {
  if (model.orm === 'mongoose') {
    return model
      .find({
        key: { $regex: `${key}.*` },
      })
      .then(results => results.map(({ value }) => JSON.parse(value)));
{'fraction_non_alphanumeric': 0.1885653409090909, 'fraction_numerical': 0.0, 'mean_word_length': 3.633223684210526, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6271074', 'n_tokens_mistral': 890, 'n_tokens_neox': 893, 'n_words': 198}