Fixing issue presented by test, passing Couch instance around for when it is being used in memory.
This commit is contained in:
parent
f13257bebe
commit
5470b77fb3
|
@ -1,5 +1,5 @@
|
||||||
const redis = require("../redis/authRedis")
|
const redis = require("../redis/authRedis")
|
||||||
const { getDB } = require("../db")
|
const { getCouch } = require("../db")
|
||||||
const { DocumentTypes } = require("../db/constants")
|
const { DocumentTypes } = require("../db/constants")
|
||||||
|
|
||||||
const EXPIRY_SECONDS = 3600
|
const EXPIRY_SECONDS = 3600
|
||||||
|
@ -7,8 +7,12 @@ const EXPIRY_SECONDS = 3600
|
||||||
/**
|
/**
|
||||||
* The default populate app metadata function
|
* The default populate app metadata function
|
||||||
*/
|
*/
|
||||||
const populateFromDB = async appId => {
|
const populateFromDB = async (appId, CouchDB = null) => {
|
||||||
return getDB(appId, { skip_setup: true }).get(DocumentTypes.APP_METADATA)
|
if (!CouchDB) {
|
||||||
|
CouchDB = getCouch()
|
||||||
|
}
|
||||||
|
const db = new CouchDB(appId, { skip_setup: true })
|
||||||
|
return db.get(DocumentTypes.APP_METADATA)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,12 +22,12 @@ const populateFromDB = async appId => {
|
||||||
* @param {*} appId the id of the app to get metadata from.
|
* @param {*} appId the id of the app to get metadata from.
|
||||||
* @returns {object} the app metadata.
|
* @returns {object} the app metadata.
|
||||||
*/
|
*/
|
||||||
exports.getAppMetadata = async appId => {
|
exports.getAppMetadata = async (appId, CouchDB = null) => {
|
||||||
const client = await redis.getAppClient()
|
const client = await redis.getAppClient()
|
||||||
// try cache
|
// try cache
|
||||||
let metadata = await client.get(appId)
|
let metadata = await client.get(appId)
|
||||||
if (!metadata) {
|
if (!metadata) {
|
||||||
metadata = await populateFromDB(appId)
|
metadata = await populateFromDB(appId, CouchDB)
|
||||||
client.store(appId, metadata, EXPIRY_SECONDS)
|
client.store(appId, metadata, EXPIRY_SECONDS)
|
||||||
}
|
}
|
||||||
return metadata
|
return metadata
|
||||||
|
|
|
@ -4,8 +4,8 @@ module.exports.setDB = pouch => {
|
||||||
Pouch = pouch
|
Pouch = pouch
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.getDB = (dbName, opts = {}) => {
|
module.exports.getDB = dbName => {
|
||||||
return new Pouch(dbName, opts)
|
return new Pouch(dbName)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.getCouch = () => {
|
module.exports.getCouch = () => {
|
||||||
|
|
|
@ -54,6 +54,9 @@ exports.isProdAppID = appId => {
|
||||||
}
|
}
|
||||||
|
|
||||||
function isDevApp(app) {
|
function isDevApp(app) {
|
||||||
|
if (!app) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
return exports.isDevAppID(app.appId)
|
return exports.isDevAppID(app.appId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,16 +236,16 @@ exports.getAllApps = async (CouchDB, { dev, all, idsOnly } = {}) => {
|
||||||
if (idsOnly) {
|
if (idsOnly) {
|
||||||
return appDbNames
|
return appDbNames
|
||||||
}
|
}
|
||||||
const appPromises = appDbNames.map(db =>
|
const appPromises = appDbNames.map(app =>
|
||||||
// skip setup otherwise databases could be re-created
|
// skip setup otherwise databases could be re-created
|
||||||
getAppMetadata(db)
|
getAppMetadata(app, CouchDB)
|
||||||
)
|
)
|
||||||
if (appPromises.length === 0) {
|
if (appPromises.length === 0) {
|
||||||
return []
|
return []
|
||||||
} else {
|
} else {
|
||||||
const response = await Promise.allSettled(appPromises)
|
const response = await Promise.allSettled(appPromises)
|
||||||
const apps = response
|
const apps = response
|
||||||
.filter(result => result.status === "fulfilled")
|
.filter(result => result.status === "fulfilled" && result.value != null)
|
||||||
.map(({ value }) => value)
|
.map(({ value }) => value)
|
||||||
if (!all) {
|
if (!all) {
|
||||||
return apps.filter(app => {
|
return apps.filter(app => {
|
||||||
|
|
|
@ -43,11 +43,7 @@ exports.save = async ctx => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const parseBooleanParam = param => {
|
const parseBooleanParam = param => {
|
||||||
if (param && param === "false") {
|
return !(param && param === "false")
|
||||||
return false
|
|
||||||
} else {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.adminUser = async ctx => {
|
exports.adminUser = async ctx => {
|
||||||
|
|
Loading…
Reference in New Issue