mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
Fix active client session index
This commit is contained in:
@@ -0,0 +1,40 @@
|
|||||||
|
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||||
|
|
||||||
|
export class FixClientSessionActiveIndex1781320000000 implements MigrationInterface {
|
||||||
|
public name = 'FixClientSessionActiveIndex1781320000000';
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`DROP INDEX IF EXISTS "IDX_unique_nonce"`);
|
||||||
|
await queryRunner.query(`
|
||||||
|
DELETE FROM "client_entity"
|
||||||
|
WHERE ctid IN (
|
||||||
|
SELECT ctid
|
||||||
|
FROM (
|
||||||
|
SELECT
|
||||||
|
ctid,
|
||||||
|
row_number() OVER (
|
||||||
|
PARTITION BY "sessionId"
|
||||||
|
ORDER BY "updatedAt" DESC, "createdAt" DESC, "id" DESC
|
||||||
|
) AS rn
|
||||||
|
FROM "client_entity"
|
||||||
|
WHERE "deletedAt" IS NULL
|
||||||
|
) duplicates
|
||||||
|
WHERE rn > 1
|
||||||
|
)
|
||||||
|
`);
|
||||||
|
await queryRunner.query(`
|
||||||
|
CREATE UNIQUE INDEX "IDX_unique_nonce"
|
||||||
|
ON "client_entity" ("sessionId")
|
||||||
|
WHERE "deletedAt" IS NULL
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`DROP INDEX IF EXISTS "IDX_unique_nonce"`);
|
||||||
|
await queryRunner.query(`
|
||||||
|
CREATE UNIQUE INDEX "IDX_unique_nonce"
|
||||||
|
ON "client_entity" ("sessionId")
|
||||||
|
WHERE "deletedAt" IS NULL
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,6 +18,7 @@ import { PayoutModes1781300000000 } from './ORM/_migrations/PayoutModes178130000
|
|||||||
import { ShareRollupStoragePolicy1781305000000 } from './ORM/_migrations/ShareRollupStoragePolicy1781305000000';
|
import { ShareRollupStoragePolicy1781305000000 } from './ORM/_migrations/ShareRollupStoragePolicy1781305000000';
|
||||||
import { AcceptedShareHighScores1781309000000 } from './ORM/_migrations/AcceptedShareHighScores1781309000000';
|
import { AcceptedShareHighScores1781309000000 } from './ORM/_migrations/AcceptedShareHighScores1781309000000';
|
||||||
import { UserAgentReportNonzeroHashrate1781313000000 } from './ORM/_migrations/UserAgentReportNonzeroHashrate1781313000000';
|
import { UserAgentReportNonzeroHashrate1781313000000 } from './ORM/_migrations/UserAgentReportNonzeroHashrate1781313000000';
|
||||||
|
import { FixClientSessionActiveIndex1781320000000 } from './ORM/_migrations/FixClientSessionActiveIndex1781320000000';
|
||||||
import { UserAgentReportView } from './ORM/_views/user-agent-report/user-agent-report.view';
|
import { UserAgentReportView } from './ORM/_views/user-agent-report/user-agent-report.view';
|
||||||
import { AcceptedShareEntity } from './ORM/accepted-share/accepted-share.entity';
|
import { AcceptedShareEntity } from './ORM/accepted-share/accepted-share.entity';
|
||||||
import { AddressSettingsEntity } from './ORM/address-settings/address-settings.entity';
|
import { AddressSettingsEntity } from './ORM/address-settings/address-settings.entity';
|
||||||
@@ -62,6 +63,7 @@ export const databaseMigrations = [
|
|||||||
ShareRollupStoragePolicy1781305000000,
|
ShareRollupStoragePolicy1781305000000,
|
||||||
AcceptedShareHighScores1781309000000,
|
AcceptedShareHighScores1781309000000,
|
||||||
UserAgentReportNonzeroHashrate1781313000000,
|
UserAgentReportNonzeroHashrate1781313000000,
|
||||||
|
FixClientSessionActiveIndex1781320000000,
|
||||||
];
|
];
|
||||||
|
|
||||||
export function createDatabaseOptions(env: NodeJS.ProcessEnv): TypeOrmModuleOptions & DataSourceOptions {
|
export function createDatabaseOptions(env: NodeJS.ProcessEnv): TypeOrmModuleOptions & DataSourceOptions {
|
||||||
|
|||||||
@@ -146,12 +146,17 @@ export class StratumV1Service implements OnModuleInit {
|
|||||||
|
|
||||||
const currentClient = client;
|
const currentClient = client;
|
||||||
client = null;
|
client = null;
|
||||||
|
let initializedClient = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (currentClient != null) {
|
if (currentClient != null) {
|
||||||
const initializedClient = protocol === 'v2'
|
initializedClient = protocol === 'v2'
|
||||||
|| (currentClient as StratumV1Client).extraNonceAndSessionId != null;
|
|| (currentClient as StratumV1Client).extraNonceAndSessionId != null;
|
||||||
await currentClient.destroy();
|
try {
|
||||||
|
await currentClient.destroy();
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Failed to clean up Stratum client after ${reason}: ${error.message}`);
|
||||||
|
}
|
||||||
if (initializedClient) {
|
if (initializedClient) {
|
||||||
if (reason == 'Error') {
|
if (reason == 'Error') {
|
||||||
this.errorClosure++;
|
this.errorClosure++;
|
||||||
|
|||||||
Reference in New Issue
Block a user