Store shortlinks with both 6 and 9 character prefixs in dynamodb

This commit is contained in:
Austin Morton
2021-04-09 17:47:14 -04:00
parent c85681e458
commit 80fa894cd0
2 changed files with 32 additions and 4 deletions

View File

@@ -74,6 +74,20 @@ export class StorageS3 extends StorageBase {
creation_date: {S: now.toISOString()},
},
}).promise(),
// temporary extra store with 6 character prefix for #2582
this.dynamoDb.putItem({
TableName: this.table,
Item: {
prefix: {S: item.prefix.substring(0, 6)},
unique_subhash: {S: item.uniqueSubHash},
full_hash: {S: item.fullHash},
stats: {
M: {clicks: {N: '0'}},
},
creation_ip: {S: ip},
creation_date: {S: now.toISOString()},
},
}).promise(),
this.s3.put(item.fullHash, item.config, this.prefix, {}),
]);
return item;

View File

@@ -151,13 +151,13 @@ describe('Stores to s3', () => {
it('and works ok', () => {
const storage = new StorageS3(httpRootDir, compilerProps, awsProps);
const object = {
prefix: 'ABCDEF',
prefix: 'ABCDEFG',
uniqueSubHash: 'ABCDEFG',
fullHash: 'ABCDEFGHIJKLMNOP',
config: 'yo',
};
const ran = {s3: false, dynamo: false};
const ran = {s3: false, dynamo: 0};
s3PutObjectHandlers.push((q) => {
q.Bucket.should.equal('bucket');
q.Key.should.equal('prefix/ABCDEFGHIJKLMNOP');
@@ -165,6 +165,20 @@ describe('Stores to s3', () => {
ran.s3 = true;
return {};
});
dynamoDbPutItemHandlers.push((q) => {
q.TableName.should.equals('table');
q.Item.should.deep.equals({
prefix: {S: 'ABCDEFG'},
unique_subhash: {S: 'ABCDEFG'},
full_hash: {S: 'ABCDEFGHIJKLMNOP'},
stats: {M: {clicks: {N: '0'}}},
creation_ip: {S: 'localhost'},
// Cheat the date
creation_date: {S: q.Item.creation_date.S},
});
ran.dynamo += 1;
return {};
});
dynamoDbPutItemHandlers.push((q) => {
q.TableName.should.equals('table');
q.Item.should.deep.equals({
@@ -176,11 +190,11 @@ describe('Stores to s3', () => {
// Cheat the date
creation_date: {S: q.Item.creation_date.S},
});
ran.dynamo = true;
ran.dynamo += 1;
return {};
});
return storage.storeItem(object, {get: () => 'localhost'}).then(() => {
ran.should.deep.equal({s3: true, dynamo: true});
ran.should.deep.equal({s3: true, dynamo: 2});
});
});
});