Skip to content
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

Merged
merged 37 commits into from
Dec 9, 2019
Merged

Implement Caching for Mapping #319

merged 37 commits into from
Dec 9, 2019

Conversation

hwong0305
Copy link
Collaborator

const updatedDomains = { ...domains }
delete updatedDomains[deletedDomain.fullDomain]
// Setting data as array to retain data structure of existing sites
setData('mappings', Object.values(updatedDomains))
Copy link
Collaborator Author

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 | {} = {}
Copy link
Collaborator

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(
Copy link
Collaborator

@songz songz Dec 7, 2019

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
}),
{}
)
Copy link
Collaborator

@songz songz Dec 7, 2019

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
}),
{}
)
}
Copy link
Collaborator

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 )

@@ -106,7 +106,7 @@ Promise.all([
fetch('/api/statuses').then(r => r.json())
]).then(([mappings, statuses]: [Mapping[], Status[]]) => {
domainList.innerHTML = ''
mappings
Object.values(mappings)
Copy link
Collaborator

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.

@@ -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]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getMappingByDomain(fullDomain)

src/lib/data.ts Show resolved Hide resolved
@songz songz merged commit a1545f6 into garageScript:master Dec 9, 2019
hwong0305 added a commit to hwong0305/myProxy that referenced this pull request Oct 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants