Skip to content

Commit

Permalink
fix: obtain datastore values directly instead of from metadata (#57)
Browse files Browse the repository at this point in the history
* refactor: remove unused constant

* fix: obtain datastore values directly instead of from metadata
  • Loading branch information
mediremi authored Jun 1, 2021
1 parent e1eb6b6 commit 749edd7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
1 change: 0 additions & 1 deletion src/constants/apiUrls.js

This file was deleted.

18 changes: 6 additions & 12 deletions src/utils/api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { getInstance } from 'd2'
import { API_URL } from '../constants/apiUrls'

export class Cache {
constructor() {
Expand Down Expand Up @@ -64,22 +63,17 @@ class Api {
return this.cache.get(namespace, key)
}

const result = await this.getMetaData(namespace, key)
const jsonLength = result.value.length
const d2 = await getInstance()
const dataStore = await d2.dataStore.get(namespace, false)
const res = await dataStore.get(key)
const value = {
length: jsonLength,
value: JSON.parse(result.value),
value: res,
length: JSON.stringify(res).length,
}
this.cache.set(namespace, key, value)
return value
}

getMetaData = async (namespace, key) => {
const d2 = await getInstance()
const response = await d2.dataStore.get(namespace, false)
return response.getMetaData(key)
}

createValue = async (namespace, key, value) => {
const d2 = await getInstance()
const resName = await d2.dataStore.get(namespace, false)
Expand Down Expand Up @@ -108,5 +102,5 @@ class Api {
}
}

const apiInstance = new Api(API_URL)
const apiInstance = new Api()
export default apiInstance

0 comments on commit 749edd7

Please sign in to comment.