<commit_before>import Vue from 'vue'
import { ActionTree } from "vuex"
import { quickSearchByQuery } from '@vue-storefront/store/lib/search'
import * as types from './mutation-types'
import SearchQuery from '@vue-storefront/store/lib/search/searchQuery'
import RootState from '@vue-storefront/store/types/RootState';
import { entityKeyName } from '@vue-storefront/store/lib/entities'
import CmsBlockState from "../../types/CmsBlockState"
import store from '@vue-storefront/store'
import { cmsBlockStorageKey } from './'
import { cacheStorage } from '../../'

const actions: ActionTree<CmsBlockState, RootState> = {

  /**
   * Retrieve cms blocks
   *
   * @param context
   * @param {any} filterValues
   * @param {any} filterField
   * @param {any} size
   * @param {any} start
   * @param {any} excludeFields
   * @param {any} includeFields
   * @returns {Promise<T> & Promise<any>}
   */
  list (context, { filterValues = null, filterField = 'identifier', size = 150, start = 0, excludeFields = null, includeFields = null, skipCache = false }) {
    let query = new SearchQuery()
    if (filterValues) {
      query = query.applyFilter({key: filterField, value: {'like': filterValues}})
    }
    if (skipCache || (!context.state.items || context.state.items.length === 0)) {
      return quickSearchByQuery({ query, entityType: 'cms_block', excludeFields, includeFields })
      .then((resp) => {
        context.commit(types.CMS_BLOCK_UPDATE_CMS_BLOCKS, resp.items)
        return resp.items
      })
      .catch(err => {
        console.error(err)
      })
    } else {
      return new Promise((resolve, reject) => {
        let resp = context.state.items
        resolve(resp)
      })
    }
  },

  /**
   * Retrieve single cms block by key value
   *
   * @param context
   * @param {any} key
   * @param {any} value
   * @param {any} excludeFields
   * @param {any} includeFields
   * @returns {Promise<T> & Promise<any>}
   */
  single (context, { key = 'identifier', value, excludeFields = null, includeFields = null, skipCache = false }) {
    const state = context.state
    if (skipCache || (!state.items || state.items.length === 0)) {
      let query = new SearchQuery()
      if (value) {
        query = query.applyFilter({key: key, value: {'like': value}})
      }
      return quickSearchByQuery({ query, entityType: 'cms_block', excludeFields, includeFields })
      .then((resp) => {
        context.commit(types.CMS_BLOCK_ADD_CMS_BLOCK, resp.items[0])
        return resp.items[0]
      })
      .catch(err => {
        console.error(err)
      })
    } else {
      return new Promise((resolve, reject) => {
        if (state.items.length > 0) {
          let cmsBlock = state.items.find((itm) => { return itm[key] === value })
          if (cmsBlock) {
            resolve(cmsBlock)
          } else {
            reject(new Error('CMS block query returned empty result ' + key + ' = ' + value))
          }
        } else {
          resolve()
        }
      })
    }
  },

  addItem ({ commit }, block) {
    commit(types.CMS_BLOCK_ADD_CMS_BLOCK, block )
  }
}

export default actions
<commit_msg>CMS block action clean up<commit_after>import { ActionTree } from "vuex"
import { quickSearchByQuery } from '@vue-storefront/store/lib/search'
import * as types from './mutation-types'
import SearchQuery from '@vue-storefront/store/lib/search/searchQuery'
import RootState from '@vue-storefront/store/types/RootState';
import CmsBlockState from "../../types/CmsBlockState"

const actions: ActionTree<CmsBlockState, RootState> = {

  /**
   * Retrieve cms blocks
   *
   * @param context
   * @param {any} filterValues
   * @param {any} filterField
   * @param {any} size
   * @param {any} start
   * @param {any} excludeFields
   * @param {any} includeFields
   * @returns {Promise<T> & Promise<any>}
   */
  list (context, { filterValues = null, filterField = 'identifier', size = 150, start = 0, excludeFields = null, includeFields = null, skipCache = false }) {
    let query = new SearchQuery()
    if (filterValues) {
      query = query.applyFilter({key: filterField, value: {'like': filterValues}})
    }
    if (skipCache || (!context.state.items || context.state.items.length === 0)) {
      return quickSearchByQuery({ query, entityType: 'cms_block', excludeFields, includeFields })
      .then((resp) => {
        context.commit(types.CMS_BLOCK_UPDATE_CMS_BLOCKS, resp.items)
        return resp.items
      })
      .catch(err => {
        console.error(err)
      })
    } else {
      return new Promise((resolve, reject) => {
        let resp = context.state.items
        resolve(resp)
      })
    }
  },

  /**
   * Retrieve single cms block by key value
   *
   * @param context
   * @param {any} key
   * @param {any} value
   * @param {any} excludeFields
   * @param {any} includeFields
   * @returns {Promise<T> & Promise<any>}
   */
  single (context, { key = 'identifier', value, excludeFields = null, includeFields = null, skipCache = false }) {
    const state = context.state
    if (skipCache || (!state.items || state.items.length === 0)) {
      let query = new SearchQuery()
      if (value) {
        query = query.applyFilter({key: key, value: {'like': value}})
      }
      return quickSearchByQuery({ query, entityType: 'cms_block', excludeFields, includeFields })
      .then((resp) => {
        context.commit(types.CMS_BLOCK_ADD_CMS_BLOCK, resp.items[0])
        return resp.items[0]
      })
      .catch(err => {
        console.error(err)
      })
    } else {
      return new Promise((resolve, reject) => {
        if (state.items.length > 0) {
          let cmsBlock = state.items.find((itm) => { return itm[key] === value })
          if (cmsBlock) {
            resolve(cmsBlock)
          } else {
            reject(new Error('CMS block query returned empty result ' + key + ' = ' + value))
          }
        } else {
          resolve()
        }
      })
    }
  },

  addItem ({ commit }, block) {
    commit(types.CMS_BLOCK_ADD_CMS_BLOCK, block )
  }
}

export default actions

{'fraction_non_alphanumeric': 0.1412308199967002, 'fraction_numerical': 0.0029698069625474343, 'mean_word_length': 2.6851063829787236, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 29, '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': '3210407', 'n_tokens_mistral': 1870, 'n_tokens_neox': 1837, 'n_words': 456}