Skip to content

Commit

Permalink
Remove loadout shares PG impl
Browse files Browse the repository at this point in the history
  • Loading branch information
bhollis committed Dec 21, 2024
1 parent 41933ea commit 210ef5c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 296 deletions.
98 changes: 0 additions & 98 deletions api/db/loadout-share-queries.test.ts

This file was deleted.

142 changes: 0 additions & 142 deletions api/db/loadout-share-queries.ts

This file was deleted.

29 changes: 6 additions & 23 deletions api/routes/loadout-share.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import crypto from 'crypto';
import asyncHandler from 'express-async-handler';
import base32 from 'hi-base32';
import { transaction } from '../db/index.js';
import { getLoadoutShare, recordAccess } from '../db/loadout-share-queries.js';
import { metrics } from '../metrics/index.js';
import { ApiApp } from '../shapes/app.js';
import {
Expand Down Expand Up @@ -54,7 +52,7 @@ export const loadoutShareHandler = asyncHandler(async (req, res) => {
});
}

const validationResult = validateLoadout('loadout_share', loadout, appId);
const validationResult = validateLoadout('loadout_share', loadout);
if (validationResult) {
res.status(400).send(validationResult);
return;
Expand Down Expand Up @@ -117,25 +115,10 @@ export const getLoadoutShareHandler = asyncHandler(async (req, res) => {
});

export async function loadLoadoutShare(shareId: string) {
// First look in Stately
try {
const loadout = await getLoadoutShareStately(shareId);
if (loadout) {
// Record when this was viewed and increment the view counter. Not using it much for now but I'd like to know.
await recordAccessStately(shareId);
return loadout;
}
} catch (e) {
console.error('Failed to load loadout share from Stately', e);
}

// Fall back to Postgres
return transaction(async (client) => {
const loadout = await getLoadoutShare(client, shareId);
if (loadout) {
// Record when this was viewed and increment the view counter. Not using it much for now but I'd like to know.
await recordAccess(client, shareId);
}
const loadout = await getLoadoutShareStately(shareId);
if (loadout) {
// Record when this was viewed and increment the view counter. Not using it much for now but I'd like to know.
await recordAccessStately(shareId);
return loadout;
});
}
}
10 changes: 5 additions & 5 deletions api/stately/init/migrate-loadout-shares.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { migrateLoadoutShareChunk } from '../migrator/loadout-shares.js';
// import { migrateLoadoutShareChunk } from '../migrator/loadout-shares.js';

while (true) {
await migrateLoadoutShareChunk();
console.log('Migrated loadout shares');
}
// while (true) {
// await migrateLoadoutShareChunk();
// console.log('Migrated loadout shares');
// }
14 changes: 0 additions & 14 deletions api/stately/migrator/index.ts

This file was deleted.

28 changes: 14 additions & 14 deletions api/stately/migrator/loadout-shares.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { transaction } from '../../db/index.js';
import { deleteLoadoutShares, getLoadoutShares } from '../../db/loadout-share-queries.js';
import { addLoadoutSharesForMigration } from '../loadout-share-queries.js';
// import { transaction } from '../../db/index.js';
// import { deleteLoadoutShares, getLoadoutShares } from '../../db/loadout-share-queries.js';
// import { addLoadoutSharesForMigration } from '../loadout-share-queries.js';

export async function migrateLoadoutShareChunk() {
await transaction(async (db) => {
const loadouts = await getLoadoutShares(db, 50);
await Promise.all(loadouts.map((loadout) => addLoadoutSharesForMigration([loadout])));
console.log('Added to stately');
await deleteLoadoutShares(
db,
loadouts.map((loadout) => loadout.shareId),
);
});
}
// export async function migrateLoadoutShareChunk() {
// await transaction(async (db) => {
// const loadouts = await getLoadoutShares(db, 50);
// await Promise.all(loadouts.map((loadout) => addLoadoutSharesForMigration([loadout])));
// console.log('Added to stately');
// await deleteLoadoutShares(
// db,
// loadouts.map((loadout) => loadout.shareId),
// );
// });
// }

0 comments on commit 210ef5c

Please sign in to comment.