mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 14:13:43 +01:00
Merge pull request #4106 from overleaf/ta-sync-user-entitlement-lean
Reduce Memory Footprint of Sync User Entitlements Script GitOrigin-RevId: 673ea76f8af9e5be6ff99b8e340414a434c203f4
This commit is contained in:
@@ -23,7 +23,11 @@ syncUserEntitlements(userEntitlements, cachedEntitlements)
|
||||
|
||||
async function syncUserEntitlements(userEntitlements, cachedEntitlements) {
|
||||
// check for user entitlements in mongo but not in postgres
|
||||
for (const userEntitlement of Object.values(userEntitlements)) {
|
||||
for (const key of Object.keys(userEntitlements)) {
|
||||
const userEntitlement = userEntitlements[key]
|
||||
if (!userEntitlement) {
|
||||
continue
|
||||
}
|
||||
// find any email(s) that are linked through sso
|
||||
for (const email of userEntitlement.emails) {
|
||||
if (!email.samlProviderId) {
|
||||
@@ -83,7 +87,11 @@ async function syncUserEntitlements(userEntitlements, cachedEntitlements) {
|
||||
}
|
||||
|
||||
// check for user entitlements in postgres but not in mongo
|
||||
for (const cachedEntitlment of Object.values(cachedEntitlements)) {
|
||||
for (const key of Object.keys(cachedEntitlements)) {
|
||||
const cachedEntitlment = cachedEntitlements[key]
|
||||
if (!cachedEntitlment) {
|
||||
continue
|
||||
}
|
||||
if (!cachedEntitlment.hasEntitlement) {
|
||||
continue
|
||||
}
|
||||
@@ -134,13 +142,15 @@ async function syncUserEntitlement(userId, email, hasEntitlement) {
|
||||
}
|
||||
|
||||
function loadUserEntitlements(userEntitlementsFilename) {
|
||||
const userEntitlementsFile = fs.readFileSync(userEntitlementsFilename, {
|
||||
encoding: 'utf8',
|
||||
})
|
||||
const userEntitlementsData = fs
|
||||
.readFileSync(userEntitlementsFilename, {
|
||||
encoding: 'utf8',
|
||||
})
|
||||
.split('\n')
|
||||
|
||||
const userEntitlements = {}
|
||||
|
||||
for (const userEntitlementLine of userEntitlementsFile.split('\n')) {
|
||||
for (const userEntitlementLine of userEntitlementsData) {
|
||||
if (!userEntitlementLine) {
|
||||
continue
|
||||
}
|
||||
@@ -155,13 +165,15 @@ function loadUserEntitlements(userEntitlementsFilename) {
|
||||
}
|
||||
|
||||
function loadCachedEntitlements(cachedEntitlementsFilename) {
|
||||
const cachedEntitlementsFile = fs.readFileSync(cachedEntitlementsFilename, {
|
||||
encoding: 'utf8',
|
||||
})
|
||||
const cachedEntitlementsData = fs
|
||||
.readFileSync(cachedEntitlementsFilename, {
|
||||
encoding: 'utf8',
|
||||
})
|
||||
.split('\n')
|
||||
|
||||
const cachedEntitlements = {}
|
||||
|
||||
for (const cachedEntitlementLine of cachedEntitlementsFile.split('\n')) {
|
||||
for (const cachedEntitlementLine of cachedEntitlementsData) {
|
||||
// this is safe because comma is not an allowed value for any column
|
||||
const [
|
||||
userId,
|
||||
|
||||
Reference in New Issue
Block a user