Skip to content

Commit

Permalink
Merge pull request #1134 from Giveth/staging
Browse files Browse the repository at this point in the history
Next release
  • Loading branch information
mohammadranjbarz authored Oct 8, 2023
2 parents 6bc312e + c65575f commit 7edd1f4
Show file tree
Hide file tree
Showing 34 changed files with 1,369 additions and 149 deletions.
1 change: 1 addition & 0 deletions .github/workflows/staging-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ jobs:
OPTIMISTIC_SCAN_API_KEY: ${{ secrets.OPTIMISTIC_SCAN_API_KEY }}
CELO_SCAN_API_KEY: ${{ secrets.CELO_SCAN_API_KEY }}
CELO_ALFAJORES_SCAN_API_KEY: ${{ secrets.CELO_ALFAJORES_SCAN_API_KEY }}
DROP_DATABASE: ${{ secrets.DROP_DATABASE }}

publish:
needs: test
Expand Down
8 changes: 8 additions & 0 deletions config/example.env
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,11 @@ POWER_BALANCE_AGGREGATOR_ADAPTER=powerBalanceAggregator
#POWER_BALANCE_AGGREGATOR_ADAPTER=mock
NUMBER_OF_BALANCE_AGGREGATOR_BATCH=20

# OPTIONAL - default: 60000 (1 minute
QF_ROUND_ESTIMATED_MATCHING_CACHE_DURATION=60000

# OPTIONAL - default: Every 10 minutes
PROJECT_CAMPAIGNS_CACHE_DURATION=600000

# OPTIONAL - default: *0 */5 * * * ( Every 5 minutes)
CACHE_PROJECT_CAMPAIGNS_CRONJOB_EXPRESSION=0 */5 * * * *
10 changes: 10 additions & 0 deletions config/test.env
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,13 @@ OPTIMISM_NODE_HTTP_URL=https://optimism-mainnet.public.blastapi.io
BALANCE_AGGREGATOR_BASE_URL=https://dev.serve.giveth.io/givpower-balance-aggregator
POWER_BALANCE_AGGREGATOR_ADAPTER=mock
NUMBER_OF_BALANCE_AGGREGATOR_BATCH=7


# ! millisecond cache, if we increase cache in test ENV we might get some errors in tests
QF_ROUND_ESTIMATED_MATCHING_CACHE_DURATION=1
# ! millisecond cache, if we increase cache in test ENV we might get some errors in tests
PROJECT_CAMPAIGNS_CACHE_DURATION=1


# OPTIONAL - default: *0 */5 * * * ( Every 5 minutes)
CACHE_PROJECT_CAMPAIGNS_CRONJOB_EXPRESSION=0 */5 * * * *
16 changes: 16 additions & 0 deletions migration/1694295208252-AddEligibleNetworksToQfRoundEntity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm';

export class AddEligibleNetworksToQfRoundEntity1694295208252
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
ALTER TABLE public.qf_round
ADD COLUMN IF NOT EXISTS "eligibleNetworks" integer array DEFAULT ARRAY[]::integer[]
`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropColumn('qf_round', 'eligibleNetworks');
}
}
32 changes: 32 additions & 0 deletions migration/1694635872128-AddEligibleNetworksToPreviousQfRounds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
import config from '../src/config';

export class AddEligibleNetworksToPreviousQfRounds1694635872128
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
const environment = config.get('ENVIRONMENT') as string;

// Define the eligible network IDs based on the conditions
const eligibleNetworks =
environment !== 'production'
? [1, 3, 5, 100, 137, 10, 420, 56, 42220, 44787] // Include testnets for staging
: [1, 137, 56, 42220, 100, 10]; // Exclude testnets for non-staging

// Update the "qf_round" table with the new eligibleNetworks values
await queryRunner.query(
`
UPDATE public.qf_round
SET "eligibleNetworks" = $1
`,
[eligibleNetworks],
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
UPDATE public.qf_round
SET "eligibleNetworks" = '{}'
`);
}
}
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "giveth-graphql-api",
"version": "1.16.1",
"version": "1.17.0",
"description": "Backend GraphQL server for Giveth originally forked from Topia",
"main": "./dist/index.js",
"dependencies": {
Expand Down
34 changes: 30 additions & 4 deletions src/entities/ProjectEstimatedMatchingView.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import { Entity, Column, Index, PrimaryColumn } from 'typeorm';
import { Field, ObjectType } from 'type-graphql';
import {
Entity,
Column,
Index,
PrimaryColumn,
BaseEntity,
ViewEntity,
ManyToOne,
RelationId,
ViewColumn,
JoinColumn,
} from 'typeorm';
import { Project } from './project';

@Entity({ name: 'project_estimated_matching_view' })
@ViewEntity('project_estimated_matching_view', { synchronize: false })
@Index('project_estimated_matching_view_project_id_qfround_id', [
'projectId',
'qfRoundId',
Expand All @@ -13,28 +26,41 @@ import { Entity, Column, Index, PrimaryColumn } from 'typeorm';
@Index('project_estimated_matching_view_unique_donation_count', [
'uniqueDonationCount',
])
export class ProjectEstimatedMatchingView {
// Project ID associated with the donations
@ObjectType()
export class ProjectEstimatedMatchingView extends BaseEntity {
@Field(type => Project)
@ManyToOne(type => Project, project => project.projectEstimatedMatchingView)
@JoinColumn({ referencedColumnName: 'id' })
project: Project;

@Field()
@ViewColumn()
@PrimaryColumn()
projectId: number;

// QF Round ID associated with the donations
@ViewColumn()
@Field()
@PrimaryColumn()
qfRoundId: number;

// Sum of the square root of the value in USD of the donations
@ViewColumn()
@Column('double precision')
sqrtRootSum: number;

// Count of unique donations per user per project per QF round
@ViewColumn()
@Column('int')
uniqueDonationCount: number;

// Sum of the value in USD of the donations for active QF rounds where the donation status is verified
@ViewColumn()
@Column('double precision')
sumValueUsd: number;

// Count of unique donors who have verified donations for each project
@ViewColumn()
@Column('int')
uniqueDonorsCount: number;
}
17 changes: 17 additions & 0 deletions src/entities/campaign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,26 @@ export enum CampaignFilterField {
}

export enum CampaignType {
// https://github.com/Giveth/impact-graph/blob/staging/docs/campaignsInstruction.md

// In these type of projects we pick some projects to show them in campaign,
// for instance for Turkey earthquake we pick some projects.
// so we just need to add slug of those projects in Related Projects Slugs and in
// what order we add them they will be shown in frontend
ManuallySelected = 'ManuallySelected',

// Sometimes in a campaign we just want to show projects in an specified order,
// for instance we can create a campaign like ** Check projects that received most likes** so for
// this campaign you set SortField as campaign type and then you can use one of below sorting fields
SortField = 'SortField',

// Sometimes we need to filter some projects in a campaign,
// for instance Let's verified projects that accept funds on Gnosis chain,
// for this we can Add verified and acceptFundOnGnosis filters
FilterFields = 'FilterFields',

// Some campaigns don't include any project in them and they are just some banner
// like Feeling $nice? campaign in below image
WithoutProjects = 'WithoutProjects',
}

Expand Down
2 changes: 2 additions & 0 deletions src/entities/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { ProjectInstantPowerView } from '../views/projectInstantPowerView';
import { QfRound } from './qfRound';
import { ReferredEvent } from './referredEvent';
import { QfRoundHistory } from './qfRoundHistory';
import { ProjectEstimatedMatchingView } from './ProjectEstimatedMatchingView';

export const getEntities = (): DataSourceOptions['entities'] => {
return [
Expand Down Expand Up @@ -81,6 +82,7 @@ export const getEntities = (): DataSourceOptions['entities'] => {
LastSnapshotProjectPowerView,
ProjectInstantPowerView,
ProjectUserInstantPowerView,
ProjectEstimatedMatchingView,

// historic snapshots
PowerSnapshotHistory,
Expand Down
14 changes: 13 additions & 1 deletion src/entities/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ import {
getQfRoundTotalProjectsDonationsSum,
} from '../repositories/qfRoundRepository';
import { EstimatedMatching } from '../types/qfTypes';
import { Campaign } from './campaign';
import { ProjectEstimatedMatchingView } from './ProjectEstimatedMatchingView';
// tslint:disable-next-line:no-var-requires
const moment = require('moment');

Expand All @@ -75,6 +77,7 @@ export enum SortingField {
QualityScore = 'QualityScore',
GIVPower = 'GIVPower',
InstantBoosting = 'InstantBoosting',
ActiveQfRoundRaisedFunds = 'ActiveQfRoundRaisedFunds',
}

export enum FilterField {
Expand All @@ -101,7 +104,6 @@ export enum OrderField {
QualityScore = 'qualityScore',
Verified = 'verified',
Reactions = 'totalReactions',
Traceable = 'traceCampaignId',
Donations = 'totalDonations',
TraceDonations = 'totalTraceDonations',
AcceptGiv = 'givingBlocksId',
Expand Down Expand Up @@ -341,6 +343,13 @@ export class Project extends BaseEntity {
@OneToMany(type => SocialProfile, socialProfile => socialProfile.project)
socialProfiles?: SocialProfile[];

@Field(type => [ProjectEstimatedMatchingView], { nullable: true })
@OneToMany(
type => ProjectEstimatedMatchingView,
projectEstimatedMatchingView => projectEstimatedMatchingView.project,
)
projectEstimatedMatchingView?: ProjectEstimatedMatchingView[];

@Field(type => Float)
@Column({ type: 'real' })
totalDonations: number;
Expand Down Expand Up @@ -390,6 +399,9 @@ export class Project extends BaseEntity {
@Field({ nullable: true })
reaction?: Reaction;

@Field(type => [Campaign], { nullable: true })
campaigns: Campaign[];

// only projects with status active can be listed automatically
static pendingReviewSince(maximumDaysForListing: Number) {
const maxDaysForListing = moment()
Expand Down
14 changes: 13 additions & 1 deletion src/entities/qfRound.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Field, ID, ObjectType } from 'type-graphql';
import { Field, ID, ObjectType, Int } from 'type-graphql';
import {
PrimaryGeneratedColumn,
Column,
Expand Down Expand Up @@ -36,6 +36,10 @@ export class QfRound extends BaseEntity {
@Column()
minimumPassportScore: number;

@Field(type => [Int], { nullable: true }) // Define the new field as an array of integers
@Column('integer', { array: true, default: [] })
eligibleNetworks: number[];

@Field(type => Date)
@Column()
beginDate: Date;
Expand All @@ -52,4 +56,12 @@ export class QfRound extends BaseEntity {

@ManyToMany(type => Project, project => project.qfRounds)
projects: Project[];

// only projects with status active can be listed automatically
isEligibleNetwork(donationNetworkId: number): Boolean {
// when not specified, all are valid
if (this.eligibleNetworks.length === 0) return true;

return this.eligibleNetworks.includes(donationNetworkId);
}
}
Loading

0 comments on commit 7edd1f4

Please sign in to comment.