Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3518893
D13657.id45074.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D13657.id45074.diff
View Options
diff --git a/lib/actions/holder-actions.js b/lib/actions/holder-actions.js
--- a/lib/actions/holder-actions.js
+++ b/lib/actions/holder-actions.js
@@ -3,7 +3,6 @@
import invariant from 'invariant';
import * as React from 'react';
-import blobService from '../facts/blob-service.js';
import {
type AuthMetadata,
IdentityClientContext,
@@ -14,8 +13,9 @@
} from '../types/holder-types.js';
import { toBase64URL } from '../utils/base64.js';
import {
- makeBlobServiceEndpointURL,
generateBlobHolder,
+ assignMultipleHolders,
+ removeMultipleHolders,
} from '../utils/blob-service.js';
import { useDispatchActionPromise } from '../utils/redux-promise-utils.js';
import { useSelector } from '../utils/redux-utils.js';
@@ -50,8 +50,6 @@
+failed: MultipleBlobHolders,
};
-// This function can be simplified when batch holders operations
-// are implemented on Blob Service
async function performBlobServiceHolderActions(
action: 'establish' | 'remove',
inputs: MultipleBlobHolders,
@@ -61,53 +59,43 @@
return { succeeded: [], failed: [] };
}
- const endpoint =
- action === 'establish'
- ? blobService.httpEndpoints.ASSIGN_HOLDER
- : blobService.httpEndpoints.DELETE_BLOB;
- const endpointURL = makeBlobServiceEndpointURL(endpoint);
const defaultHeaders = createDefaultHTTPRequestHeaders(authMetadata);
+ const blobServiceCall =
+ action === 'establish' ? assignMultipleHolders : removeMultipleHolders;
+
+ const requestInputs = inputs.map(({ blobHash, ...rest }) => ({
+ ...rest,
+ blobHash: toBase64URL(blobHash),
+ }));
+ const response = await blobServiceCall(requestInputs, defaultHeaders);
+ if (response.result === 'success') {
+ return { succeeded: inputs, failed: [] };
+ }
+ if (response.result === 'error') {
+ return { succeeded: [], failed: inputs };
+ }
- const promises = inputs.map(async input => {
- const blobHash = toBase64URL(input.blobHash);
- try {
- const response = await fetch(endpointURL, {
- method: endpoint.method,
- body: JSON.stringify({
- holder: input.holder,
- blob_hash: blobHash,
- }),
- headers: {
- ...defaultHeaders,
- 'content-type': 'application/json',
- },
- });
- const holderAlreadyEstablishedResponse =
- action === 'establish' && response.status === 409;
- if (response.ok || holderAlreadyEstablishedResponse) {
- return { ...input, success: true };
- }
- return { ...input, success: false };
- } catch (e) {
- return { ...input, success: false };
- }
- });
+ const failedRequestsSet = new Set(
+ response.failedRequests.map(({ blobHash, holder }) =>
+ JSON.stringify({ blobHash, holder }),
+ ),
+ );
- const results = await Promise.all(promises);
const succeeded = [],
failed = [];
- for (const { success, ...holderEntry } of results) {
- if (success) {
- succeeded.push(holderEntry);
+ for (const item of inputs) {
+ const stringifiedItem = JSON.stringify({
+ blobHash: toBase64URL(item.blobHash),
+ holder: item.holder,
+ });
+ if (failedRequestsSet.has(stringifiedItem)) {
+ failed.push(item);
} else {
- failed.push(holderEntry);
+ succeeded.push(item);
}
}
- return {
- succeeded,
- failed,
- };
+ return { succeeded, failed };
}
async function processHoldersAction(
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 23, 9:00 PM (19 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2696394
Default Alt Text
D13657.id45074.diff (3 KB)
Attached To
Mode
D13657: [lib] Use batch Blob service endpoints in processHolders action
Attached
Detach File
Event Timeline
Log In to Comment