-
Notifications
You must be signed in to change notification settings - Fork 583
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(app-page-builder): improve blocks loading and data compression (#…
- Loading branch information
Showing
77 changed files
with
2,154 additions
and
748 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/api-page-builder-so-ddb-es/src/operations/pageBlock/compression.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { compress as gzip, decompress as ungzip } from "@webiny/utils/compression/gzip"; | ||
import { PageBlock } from "@webiny/api-page-builder/types"; | ||
|
||
const GZIP = "gzip"; | ||
const TO_STORAGE_ENCODING = "base64"; | ||
const FROM_STORAGE_ENCODING = "utf8"; | ||
|
||
const convertToBuffer = (value: string | Buffer) => { | ||
if (typeof value === "string") { | ||
return Buffer.from(value, TO_STORAGE_ENCODING); | ||
} | ||
return value; | ||
}; | ||
|
||
export const compress = async (data: any) => { | ||
const value = await gzip(JSON.stringify(data)); | ||
|
||
return { | ||
compression: GZIP, | ||
value: value.toString(TO_STORAGE_ENCODING) | ||
}; | ||
}; | ||
|
||
export const decompress = async (pageBlock: PageBlock) => { | ||
try { | ||
const buf = await ungzip(convertToBuffer(pageBlock.content.value)); | ||
const value = buf.toString(FROM_STORAGE_ENCODING); | ||
return { | ||
...pageBlock, | ||
content: JSON.parse(value) | ||
}; | ||
} catch (ex) { | ||
return { ...pageBlock, content: null }; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 25 additions & 4 deletions
29
packages/api-page-builder-so-ddb-es/src/operations/pageBlock/keys.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,37 @@ | ||
export interface PartitionKeyParams { | ||
tenant: string; | ||
locale: string; | ||
id: string; | ||
} | ||
|
||
export interface GSIPartitionKeyParams { | ||
tenant: string; | ||
locale: string; | ||
} | ||
|
||
export interface GSISortKeyParams { | ||
blockCategory: string; | ||
id: string; | ||
} | ||
|
||
export const createPartitionKey = (params: PartitionKeyParams): string => { | ||
const { tenant, locale, id } = params; | ||
return `T#${tenant}#L#${locale}#PB#BLOCK#${id}`; | ||
}; | ||
|
||
export const createGSIPartitionKey = (params: GSIPartitionKeyParams): string => { | ||
const { tenant, locale } = params; | ||
return `T#${tenant}#L#${locale}#PB#B`; | ||
return `T#${tenant}#L#${locale}#PB#BLOCKS`; | ||
}; | ||
|
||
export const createGSISortKey = (params: GSISortKeyParams): string => { | ||
const { id, blockCategory } = params; | ||
return `${blockCategory}#${id}`; | ||
}; | ||
|
||
export interface SortKeyParams { | ||
id: string; | ||
} | ||
export const createSortKey = (params: SortKeyParams): string => { | ||
const { id } = params; | ||
return id; | ||
export const createSortKey = (): string => { | ||
return "A"; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/api-page-builder-so-ddb/src/operations/pageBlock/compression.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { compress as gzip, decompress as ungzip } from "@webiny/utils/compression/gzip"; | ||
import { PageBlock } from "@webiny/api-page-builder/types"; | ||
|
||
const GZIP = "gzip"; | ||
const TO_STORAGE_ENCODING = "base64"; | ||
const FROM_STORAGE_ENCODING = "utf8"; | ||
|
||
const convertToBuffer = (value: string | Buffer) => { | ||
if (typeof value === "string") { | ||
return Buffer.from(value, TO_STORAGE_ENCODING); | ||
} | ||
return value; | ||
}; | ||
|
||
export const compress = async (data: any) => { | ||
const value = await gzip(JSON.stringify(data)); | ||
|
||
return { | ||
compression: GZIP, | ||
value: value.toString(TO_STORAGE_ENCODING) | ||
}; | ||
}; | ||
|
||
export const decompress = async (pageBlock: PageBlock) => { | ||
try { | ||
const buf = await ungzip(convertToBuffer(pageBlock.content.value)); | ||
const value = buf.toString(FROM_STORAGE_ENCODING); | ||
return { | ||
...pageBlock, | ||
content: JSON.parse(value) | ||
}; | ||
} catch (ex) { | ||
return { ...pageBlock, content: null }; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.