-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Caching for Mapping #319
Conversation
src/api/mapping.ts
Outdated
const updatedDomains = { ...domains } | ||
delete updatedDomains[deletedDomain.fullDomain] | ||
// Setting data as array to retain data structure of existing sites | ||
setData('mappings', Object.values(updatedDomains)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this line is not done, it will be incompatible with already launched myproxy servers after upgrading.
When I was testing on my droplet, the create and delete servers functionality did not work correctly since the mappings object in data.db is not in the proper format.
src/lib/data.ts
Outdated
|
||
const data: DB = { | ||
serviceKeys: [], | ||
mappings: [], | ||
availableDomains: [] | ||
} | ||
|
||
let mappingsCache: MappingObj | {} = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
domainToMapping
and idToMapping
are clearer variable names
src/lib/data.ts
Outdated
@@ -19,6 +23,22 @@ fs.readFile('./data.db', (err, file) => { | |||
data.serviceKeys = fileData.serviceKeys || [] | |||
data.mappings = fileData.mappings || [] | |||
data.availableDomains = fileData.availableDomains || [] | |||
|
|||
mappingsCache = data.mappings.reduce( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you create a helper functionn for this? I would call thhis function:
setMappingCache( data.mappings )
src/lib/data.ts
Outdated
[item.id]: item | ||
}), | ||
{} | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you create a helper functionn for this? I would call thhis function:
setMappingCache( data.mappings )
src/lib/data.ts
Outdated
}), | ||
{} | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you create a helper functionn for this? I would call thhis function:
setMappingCache( data.mappings )
src/public/client.ts
Outdated
@@ -106,7 +106,7 @@ Promise.all([ | |||
fetch('/api/statuses').then(r => r.json()) | |||
]).then(([mappings, statuses]: [Mapping[], Status[]]) => { | |||
domainList.innerHTML = '' | |||
mappings | |||
Object.values(mappings) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should keep as an array.
src/api/mapping.ts
Outdated
@@ -26,12 +26,12 @@ mappingRouter.post('/', async (req, res) => { | |||
const fullDomain = req.body.subDomain | |||
? `${req.body.subDomain}.${req.body.domain}` | |||
: `${req.body.domain}` | |||
const existingSubDomain = domainKeys.find(e => e.fullDomain === fullDomain) | |||
const existingSubDomain = domainKeys[fullDomain] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getMappingByDomain(fullDomain)
#306