src/js/INTER-Mediator.js
/* --------------------------------------------------------------------
     This implementation for cache is quite limited.
     */
This implementation for cache is quite limited.
This implementation for cache is quite limited .
async function retrieveDataFromCache(currentContextDef, relationValue, completion) {
      let targetRecords = null
      try {
        if (!INTERMediatorOnPage.dbCache[currentContextDef.name]) {
          await INTERMediator_DBAdapter.db_query_async(
            {
              name: currentContextDef.name,
              records: null,
              paging: null,
              fields: null,
              parentkeyvalue: null,
              conditions: null,
              useoffset: false
            },
            (result) => {
              INTERMediatorOnPage.dbCache[currentContextDef.name] = result
              completion(result)
            },
            null
          )
        }
        if (relationValue === null) {
          targetRecords = INTERMediatorOnPage.dbCache[currentContextDef.name]
        } else {
          targetRecords = {recordset: [], count: 0}
          let counter = 0
          for (let ix in INTERMediatorOnPage.dbCache[currentContextDef.name].dbresult) {
            if (INTERMediatorOnPage.dbCache[currentContextDef.name].dbresult.hasOwnProperty(ix)) {
              const oneRecord = INTERMediatorOnPage.dbCache[currentContextDef.name].dbresult[ix]
              let isMatch = true
              let index = 0
              for (const keyField in relationValue) {
                if (relationValue.hasOwnProperty(keyField)) {
                  const fieldName = currentContextDef.relation[index]['foreign-key']
                  if (oneRecord[fieldName] !== relationValue[keyField]) {
                    isMatch = false
                    break
                  }
                  index++
                }
              }
              if (isMatch) {
                const pagingValue = currentContextDef.paging ? currentContextDef.paging : false
                const recordsValue = currentContextDef.records ? currentContextDef.records : 10000000000
                if (!pagingValue || (pagingValue && (counter >= INTERMediator.startFrom))) {
                  targetRecords.recordset.push(oneRecord)
                  targetRecords.count++
                  if (recordsValue <= targetRecords.count) {
                    break
                  }
                }
                counter++
              }
            }
          }
          completion(targetRecords)
        }
      } catch (ex) {
        if (ex.message === '_im_auth_required_') {
          throw ex
        } else {
          INTERMediatorLog.setErrorMessage(ex, 'EXCEPTION-24')
        }
      }
    }
async function retrieveDataFromCache ( currentContextDef , relationValue , completion ) { let targetRecords = null try { if ( ! INTERMediatorOnPage . dbCache [ currentContextDef . name ] ) { await INTERMediator_DBAdapter . db_query_async ( { name : currentContextDef . name , records : null , paging : null , fields : null , parentkeyvalue : null , conditions : null , useoffset : false } , ( result ) => { INTERMediatorOnPage . dbCache [ currentContextDef . name ] = result completion ( result ) } , null ) } if ( relationValue === null ) { targetRecords = INTERMediatorOnPage . dbCache [ currentContextDef . name ] } else { targetRecords = { recordset : [ ] , count : 0 } let counter = 0 for ( let ix in INTERMediatorOnPage . dbCache [ currentContextDef . name ] . dbresult ) { if ( INTERMediatorOnPage . dbCache [ currentContextDef . name ] . dbresult . hasOwnProperty ( ix ) ) { const oneRecord = INTERMediatorOnPage . dbCache [ currentContextDef . name ] . dbresult [ ix ] let isMatch = true let index = 0 for ( const keyField in relationValue ) { if ( relationValue . hasOwnProperty ( keyField ) ) { const fieldName = currentContextDef . relation [ index ] [ 'foreign-key' ] if ( oneRecord [ fieldName ] !== relationValue [ keyField ] ) { isMatch = false break } index ++ } } if ( isMatch ) { const pagingValue = currentContextDef . paging ? currentContextDef . paging : false const recordsValue = currentContextDef . records ? currentContextDef . records : 10000000000 if ( ! pagingValue || ( pagingValue && ( counter >= INTERMediator . startFrom ) ) ) { targetRecords . recordset . push ( oneRecord ) targetRecords . count ++ if ( recordsValue <= targetRecords . count ) { break } } counter ++ } } } completion ( targetRecords ) } } catch ( ex ) { if ( ex . message === '_im_auth_required_' ) { throw ex } else { INTERMediatorLog . setErrorMessage ( ex , 'EXCEPTION-24' ) } } }
This implementation for cache is quite limited.
This implementation for cache is quite limited .