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

Compaction API #350

Merged
merged 5 commits into from Oct 28, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Export COMPACT_SYNC_CATEGORY

  • Loading branch information
darkdh committed Oct 18, 2019
commit b95ffb2b1764d5959fde45f68c824afe522fa663
@@ -99,6 +99,11 @@ const messages = {
* browser sends this to delete all records in a category.
*/
DELETE_SYNC_CATEGORY: _, /* @param {string} categoryName */
/**
* browser -> webview
* browser sends this to compact records in a category
*/
COMPACT_SYNC_CATEGORY: _, /* @param {string} categoryName */
/**
* webview -> browser
* webview sends this to delete all site settings.
@@ -429,7 +429,11 @@ RequestUtil.prototype.put = function (category, record) {
})
}

RequestUtil.prototype.compactRecords = function (category) {
/**
* Compact all records in a category
* @param {string=} category - the category ID
*/
RequestUtil.prototype.compactCategory = function (category) {
const thisCategory = category
if (!recordUtil.CATEGORY_IDS.includes(thisCategory)) {
throw new Error(`Unsupported sync category: ${category}`)
@@ -112,9 +112,6 @@ const startSync = (requester) => {
if (nextContinuationTokens[category]) {
continuationToken = nextContinuationTokens[category]
}
if (proto.categories[category] === proto.categories.BOOKMARKS) {
requester.compactRecords(proto.categories.BOOKMARKS)
}
requester.list(proto.categories[category], startAt, limitResponse, continuationToken).then((s3Objects) => {
const jsRecords = getJSRecords(s3Objects.contents)
logSync(`got ${jsRecords.length} decrypted records in ${category} after ${startAt}`)
@@ -189,6 +186,13 @@ const startSync = (requester) => {
requester.purgeUserQueue()
})
})
ipc.on(messages.COMPACT_SYNC_CATEGORY, (e, category) => {
if (!proto.categories[category]) {
throw new Error(`Unsupported sync category: ${category}`)
}
logSync(`Compacting category: ${category}`)
requester.compactCategory(proto.categories[category])
})
ipc.on(messages.DELETE_SYNC_SITE_SETTINGS, (e) => {
logSync(`Deleting siteSettings`)
requester.deleteSiteSettings().then(() => {
@@ -336,6 +336,12 @@ module.exports.deletePrefix = function (s3, bucket, prefix, deleteIf) {
})
}

/**
* Delete objects in s3
* @param {AwsSdk.S3} s3
* @param {string} bucket
* @param {Array.<string>} objects
*/
module.exports.deleteObjects = function (s3, bucket, objects) {
if (objects.length > 0) {
s3.deleteObjects({
@@ -447,7 +447,8 @@ test('client RequestUtil', (t) => {
requestUtil.put(proto.categories.BOOKMARKS, record_update)
requestUtil.put(proto.categories.BOOKMARKS, record2_update)
}
requestUtil.compactRecords(proto.categories.BOOKMARKS)
requestUtil.compactCategory(proto.categories.BOOKMARKS)
// takes about 1 minute for delete to be completely done
setTimeout(() => {
requestUtil.list(proto.categories.BOOKMARKS)
.then(s3Objects => requestUtil.s3ObjectsToRecords(s3Objects.contents))
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.