Skip to content

Commit

Permalink
Merge pull request #1105 from Giveth/feat/addFillSnapshotRoundBack
Browse files Browse the repository at this point in the history
Removed snapshot block number
  • Loading branch information
mohammadranjbarz authored Dec 18, 2023
2 parents 2483566 + 651d9e2 commit 5f16270
Show file tree
Hide file tree
Showing 16 changed files with 21 additions and 59 deletions.
14 changes: 14 additions & 0 deletions migration/1693205688573-MigrateToBalanceAggregator2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class MigrateToBalanceAggregator21693205688573
implements MigrationInterface
{
async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE IF EXISTS public.power_snapshot
DROP COLUMN "blockNumber"
`);
}

async down(queryRunner: QueryRunner): Promise<void> {}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

// tslint:disable-next-line:class-name
export class createGivPowerHistoricTablesProcedure1670429143091
export class createGivPowerHistoricTablesProcedure1693205688574
implements MigrationInterface
{
async up(queryRunner: QueryRunner): Promise<void> {
Expand Down Expand Up @@ -41,10 +41,10 @@ export class createGivPowerHistoricTablesProcedure1670429143091
FROM "power_snapshot" AS "snapshot", "power_round" AS "powerRound"
WHERE "snapshot"."roundNumber" < "powerRound"."round" - 1
)
RETURNING ps."id", ps."time", ps."blockNumber", ps."roundNumber", ps."synced"
RETURNING ps."id", ps."time", ps."roundNumber", ps."synced"
)
INSERT INTO "power_snapshot_history" ("id", "time", "blockNumber", "roundNumber", "synced")
SELECT se."id", se."time", se."blockNumber", se."roundNumber", se."synced"
INSERT INTO "power_snapshot_history" ("id", "time", "roundNumber", "synced")
SELECT se."id", se."time", se."roundNumber", se."synced"
FROM snapshot_entity AS se;
$BODY$;
`);
Expand Down
5 changes: 0 additions & 5 deletions src/entities/powerSnapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ export class PowerSnapshot extends BaseEntity {
@Index({ unique: true })
time: Date;

@Field(type => Int)
@Column('integer', { nullable: true })
@Index({ unique: true })
blockNumber?: number;

@Field()
@Column({ type: 'integer', nullable: true })
roundNumber: number;
Expand Down
12 changes: 1 addition & 11 deletions src/entities/powerSnapshotHistory.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
import { Field, ID, Int, ObjectType } from 'type-graphql';
import {
PrimaryGeneratedColumn,
Column,
Entity,
BaseEntity,
Index,
OneToMany,
PrimaryColumn,
} from 'typeorm';
import { PowerBalanceSnapshotHistory } from './powerBalanceSnapshotHistory';
import { PowerBoostingSnapshotHistory } from './powerBoostingSnapshotHistory';
import { Column, Entity, BaseEntity, Index, PrimaryColumn } from 'typeorm';

@Entity()
@ObjectType()
Expand Down
1 change: 0 additions & 1 deletion src/repositories/powerBalanceSnapshotRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ function createPowerSnapshotBalancesTestCases() {

const powerSnapshot = await PowerSnapshot.create({
time: new Date(powerSnapshotTime++),
blockNumber: powerSnapshotTime,
}).save();

await assertNotThrowsAsync(async () => {
Expand Down
9 changes: 0 additions & 9 deletions src/repositories/powerSnapshotRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ function balanceSnapshotTestCases() {
const powerSnapshots = PowerSnapshot.create([
{
time: new Date(powerSnapshotTime++),
blockNumber: 100,
},
{
time: new Date(powerSnapshotTime++),
Expand Down Expand Up @@ -375,9 +374,6 @@ function findPowerSnapshotByIdTestCases() {
assert.equal(updateFlatResponse, 0);

// firstSnapshot with blockNumber without balance saved.

firstSnapshot.blockNumber = 1000;
await firstSnapshot.save();
updateFlatResponse = await updatePowerSnapshotSyncedFlag();

assert.equal(updateFlatResponse, 0);
Expand All @@ -396,8 +392,6 @@ function findPowerSnapshotByIdTestCases() {

// Fill only the third snapshot info

thirdSnapshot.blockNumber = 3000;
await thirdSnapshot.save();
await addOrUpdatePowerSnapshotBalances({
userId: user1.id,
balance: 1,
Expand All @@ -409,9 +403,6 @@ function findPowerSnapshotByIdTestCases() {
assert.isTrue(thirdSnapshot.synced);

// Fill second and forth snapshots info
secondSnapshot.blockNumber = 2000;
forthSnapshot.blockNumber = 4000;
await PowerSnapshot.save([secondSnapshot, forthSnapshot]);
await addOrUpdatePowerSnapshotBalances([
{
userId: user1.id,
Expand Down
2 changes: 0 additions & 2 deletions src/repositories/previousRoundRankRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ const createSomeSampleProjectsAndPowerViews = async () => {
const [powerSnapshots] = await findPowerSnapshots();
const snapshot = powerSnapshots[0];

snapshot.blockNumber = 1;
snapshot.roundNumber = roundNumber;
await snapshot.save();

Expand Down Expand Up @@ -140,7 +139,6 @@ function projectsThatTheirRanksHaveChangedTestCases() {
const [powerSnapshots] = await findPowerSnapshots();
const snapshot = powerSnapshots[0];

snapshot.blockNumber = roundNumber;
snapshot.roundNumber = roundNumber;
await snapshot.save();

Expand Down
8 changes: 0 additions & 8 deletions src/repositories/projectPowerViewRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ function projectPowerViewRepositoryTestCases() {
const [powerSnapshots] = await findPowerSnapshots();
const snapshot = powerSnapshots[0];

snapshot.blockNumber = 1;
snapshot.roundNumber = roundNumber;
await snapshot.save();

Expand Down Expand Up @@ -137,7 +136,6 @@ function projectPowerViewRepositoryTestCases() {
const [powerSnapshots] = await findPowerSnapshots();
const snapshot = powerSnapshots[0];

snapshot.blockNumber = 1;
snapshot.roundNumber = roundNumber;
await snapshot.save();

Expand Down Expand Up @@ -190,7 +188,6 @@ function projectPowerViewRepositoryTestCases() {
let [powerSnapshots] = await findPowerSnapshots();
let snapshot = powerSnapshots[0];

snapshot.blockNumber = 1;
snapshot.roundNumber = roundNumber;
await snapshot.save();

Expand Down Expand Up @@ -219,7 +216,6 @@ function projectPowerViewRepositoryTestCases() {
[powerSnapshots] = await findPowerSnapshots();
snapshot = powerSnapshots[1];

snapshot.blockNumber = 2;
snapshot.roundNumber = roundNumber;
await snapshot.save();

Expand Down Expand Up @@ -277,7 +273,6 @@ function findProjectPowerViewByProjectIdTestCases() {
const [powerSnapshots] = await findPowerSnapshots();
const snapshot = powerSnapshots[0];

snapshot.blockNumber = 1;
snapshot.roundNumber = roundNumber;
await snapshot.save();

Expand Down Expand Up @@ -428,7 +423,6 @@ function projectFuturePowerViewRepositoryTestCases() {
const [powerSnapshots] = await findPowerSnapshots();
const snapshot = powerSnapshots[0];

snapshot.blockNumber = 1;
snapshot.roundNumber = roundNumber;
await snapshot.save();

Expand All @@ -448,7 +442,6 @@ function projectFuturePowerViewRepositoryTestCases() {

await takePowerBoostingSnapshot();

snapshot.blockNumber = 2;
snapshot.roundNumber = roundNumber + 1;
await snapshot.save();

Expand Down Expand Up @@ -514,7 +507,6 @@ function getBottomPowerRankTestCases() {
const [powerSnapshots] = await findPowerSnapshots();
const snapshot = powerSnapshots[0];

snapshot.blockNumber = 1;
snapshot.roundNumber = roundNumber;
await snapshot.save();

Expand Down
1 change: 0 additions & 1 deletion src/repositories/projectRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@ function orderByTotalPower() {
const [powerSnapshots] = await findPowerSnapshots();
const snapshot = powerSnapshots[0];

snapshot.blockNumber = 1;
snapshot.roundNumber = roundNumber;
await snapshot.save();

Expand Down
4 changes: 0 additions & 4 deletions src/repositories/userProjectPowerViewRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ describe('userProjectPowerViewRepository test', () => {
[powerSnapshots] = await findPowerSnapshots();
snapshot = powerSnapshots[1];

snapshot.blockNumber = 2;
snapshot.roundNumber = roundNumber;
await snapshot.save();

Expand Down Expand Up @@ -264,7 +263,6 @@ describe('userProjectPowerViewRepository test', () => {
await takePowerBoostingSnapshot();
const [powerSnapshots] = await findPowerSnapshots();
const snapshot = powerSnapshots[0];
snapshot.blockNumber = 1;
snapshot.roundNumber = roundNumber;
await snapshot.save();

Expand All @@ -277,7 +275,6 @@ describe('userProjectPowerViewRepository test', () => {
await sleep(1);
await takePowerBoostingSnapshot();

snapshot.blockNumber = 2;
snapshot.roundNumber = roundNumber;
await snapshot.save();

Expand All @@ -290,7 +287,6 @@ describe('userProjectPowerViewRepository test', () => {

await takePowerBoostingSnapshot();

snapshot.blockNumber = 3;
snapshot.roundNumber = roundNumber;
await snapshot.save();

Expand Down
1 change: 0 additions & 1 deletion src/resolvers/donationResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,6 @@ function createDonationTestCases() {
const [powerSnapshots] = await findPowerSnapshots();
const snapshot = powerSnapshots[0];

snapshot.blockNumber = 1;
snapshot.roundNumber = roundNumber;
await snapshot.save();
await addOrUpdatePowerSnapshotBalances({
Expand Down
1 change: 0 additions & 1 deletion src/resolvers/powerBoostingResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,6 @@ async function getBottomPowerRankTestCases() {

const roundNumber = firstProject.id * 10;

snapshot.blockNumber = 1;
snapshot.roundNumber = roundNumber;
await snapshot.save();

Expand Down
2 changes: 0 additions & 2 deletions src/resolvers/projectPowerResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ function projectPowersTestCases() {
const [powerSnapshots] = await findPowerSnapshots();
const snapshot = powerSnapshots[0];

snapshot.blockNumber = 1;
snapshot.roundNumber = roundNumber;
await snapshot.save();

Expand Down Expand Up @@ -146,7 +145,6 @@ function projectPowersTestCases() {
const [powerSnapshots] = await findPowerSnapshots();
const snapshot = powerSnapshots[0];

snapshot.blockNumber = 1;
snapshot.roundNumber = roundNumber - 1;
await snapshot.save();

Expand Down
3 changes: 0 additions & 3 deletions src/resolvers/projectResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,6 @@ function allProjectsTestCases() {
const [powerSnapshots] = await findPowerSnapshots();
const snapshot = powerSnapshots[0];

snapshot.blockNumber = 1;
snapshot.roundNumber = roundNumber;
await snapshot.save();

Expand Down Expand Up @@ -812,7 +811,6 @@ function allProjectsTestCases() {
const [powerSnapshots] = await findPowerSnapshots();
const snapshot = powerSnapshots[0];

snapshot.blockNumber = 1;
snapshot.roundNumber = roundNumber;
await snapshot.save();

Expand Down Expand Up @@ -5566,7 +5564,6 @@ function projectBySlugTestCases() {
const [powerSnapshots] = await findPowerSnapshots();
const snapshot = powerSnapshots[0];

snapshot.blockNumber = 1;
snapshot.roundNumber = roundNumber;
await snapshot.save();

Expand Down
5 changes: 0 additions & 5 deletions src/resolvers/userProjectPowerResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ function userProjectPowersTestCases() {
const [powerSnapshots] = await findPowerSnapshots();
const snapshot = powerSnapshots[0];

snapshot.blockNumber = 1;
snapshot.roundNumber = givbackRound;
await snapshot.save();

Expand Down Expand Up @@ -143,7 +142,6 @@ function userProjectPowersTestCases() {
const [powerSnapshots] = await findPowerSnapshots();
const snapshot = powerSnapshots[0];

snapshot.blockNumber = 1;
snapshot.roundNumber = givbackRound;
await snapshot.save();

Expand Down Expand Up @@ -230,7 +228,6 @@ function userProjectPowersTestCases() {
const [powerSnapshots] = await findPowerSnapshots();
const snapshot = powerSnapshots[0];

snapshot.blockNumber = 1;
snapshot.roundNumber = givbackRound;
await snapshot.save();

Expand Down Expand Up @@ -313,7 +310,6 @@ function userProjectPowersTestCases() {
const [powerSnapshots] = await findPowerSnapshots();
const snapshot = powerSnapshots[0];

snapshot.blockNumber = 1;
snapshot.roundNumber = givbackRound;
await snapshot.save();

Expand Down Expand Up @@ -388,7 +384,6 @@ function userProjectPowersTestCases() {
const [powerSnapshots] = await findPowerSnapshots();
const snapshot = powerSnapshots[0];

snapshot.blockNumber = 1;
snapshot.roundNumber = givbackRound;
await snapshot.save();

Expand Down
4 changes: 2 additions & 2 deletions test/pre-test-scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { UserProjectPowerView1662877385339 } from '../migration/1662877385339-Us
import { ProjectPowerView1662915983385 } from '../migration/1662915983385-ProjectPowerView';
import { TakePowerBoostingSnapshotProcedure1663594895751 } from '../migration/1663594895751-takePowerSnapshotProcedure';
import { ProjectFuturePowerView1668411738120 } from '../migration/1668411738120-ProjectFuturePowerView';
import { createGivPowerHistoricTablesProcedure1670429143091 } from '../migration/1670429143091-createGivPowerHistoricTablesProcedure';
import { createGivPowerHistoricTablesProcedure1693205688574 } from '../migration/1693205688574-createGivPowerHistoricTablesProcedure';
import { LastSnapshotProjectPowerView1671448387986 } from '../migration/1671448387986-LastSnapshotProjectPowerView';
import { AppDataSource } from '../src/orm';
import { createOrganisatioTokenTable1646302349926 } from '../migration/1646302349926-createOrganisatioTokenTable';
Expand Down Expand Up @@ -394,7 +394,7 @@ async function runMigrations() {
await new LastSnapshotProjectPowerView1671448387986().up(queryRunner);
await new ProjectFuturePowerView1668411738120().up(queryRunner);
await new TakePowerBoostingSnapshotProcedure1663594895751().up(queryRunner);
await new createGivPowerHistoricTablesProcedure1670429143091().up(
await new createGivPowerHistoricTablesProcedure1693205688574().up(
queryRunner,
);
await new createOrganisatioTokenTable1646302349926().up(queryRunner);
Expand Down

0 comments on commit 5f16270

Please sign in to comment.