Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove Favorites FF #311

Merged
merged 1 commit into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .env.spec
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@ COLLECTIONS_CHAIN_ID=137
API_VERSION=v1
HTTP_SERVER_PORT=5005
HTTP_SERVER_HOST=0.0.0.0

FF_FAVORITES=1 # TODO (lists): remove after the release of the feature
25 changes: 9 additions & 16 deletions src/adapters/sources/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@ import { IFavoritesComponent } from '../../ports/favorites/types'
import { enhanceItemsWithPicksStats } from '../../logic/favorites/utils'
import { convertItemToSortableResult } from '../../logic/items/utils'

export function createItemsSource(
components: {
itemsComponent: IItemsComponent
favoritesComponent: IFavoritesComponent
},
options?: {
isFavoritesEnabled?: boolean
}
): IMergerComponent.Source<Item, ItemFilters, ItemSortBy> {
export function createItemsSource(components: {
itemsComponent: IItemsComponent
favoritesComponent: IFavoritesComponent
}): IMergerComponent.Source<Item, ItemFilters, ItemSortBy> {
const { itemsComponent, favoritesComponent } = components

async function fetch({
Expand All @@ -22,14 +17,12 @@ export function createItemsSource(
}: FetchOptions<ItemOptions, ItemSortBy>) {
let items = await itemsComponent.fetch(filters)

if (options && options.isFavoritesEnabled) {
const picksStats = await favoritesComponent.getPicksStatsOfItems(
items.map(({ id }) => id),
pickedBy
)
const picksStats = await favoritesComponent.getPicksStatsOfItems(
items.map(({ id }) => id),
pickedBy
)

items = enhanceItemsWithPicksStats(items, picksStats)
}
items = enhanceItemsWithPicksStats(items, picksStats)

return items.map(convertItemToSortableResult)
}
Expand Down
29 changes: 9 additions & 20 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,6 @@ async function initComponents(): Promise<AppComponents> {
methods: await config.getString('CORS_METHOD'),
}

// FF_FAVORITES
const isFavoritesEnabled = (await config.getNumber('FF_FAVORITES')) === 1

const logs = await createLogComponent({ tracer })

const server = await createServerComponent<GlobalContext>(
Expand Down Expand Up @@ -451,12 +448,10 @@ async function initComponents(): Promise<AppComponents> {

const items = createMergerComponent<Item, ItemOptions, ItemSortBy>({
sources: [
createItemsSource(
{ itemsComponent: collectionsItems, favoritesComponent },
{
isFavoritesEnabled,
}
),
createItemsSource({
itemsComponent: collectionsItems,
favoritesComponent,
}),
],
defaultSortBy: ITEM_DEFAULT_SORT_BY,
directions: {
Expand Down Expand Up @@ -520,16 +515,11 @@ async function initComponents(): Promise<AppComponents> {
})

// trendings
const trendings = createTrendingsComponent(
{
collectionsSubgraphComponent: collectionsSubgraph,
itemsComponent: items,
favoritesComponent,
},
{
isFavoritesEnabled,
}
)
const trendings = createTrendingsComponent({
collectionsSubgraphComponent: collectionsSubgraph,
itemsComponent: items,
favoritesComponent,
})

// analytics day data for the marketplace subgraph
const marketplaceAnalyticsDayData =
Expand Down Expand Up @@ -709,7 +699,6 @@ async function initComponents(): Promise<AppComponents> {

const catalog = await createCatalogComponent({
favoritesComponent,
isFavoritesEnabled,
database: satsumaDatabase,
})

Expand Down
15 changes: 6 additions & 9 deletions src/ports/catalog/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ import { getItemIdsBySearchTextQuery, getLatestSubgraphSchema } from './queries'
export function createCatalogComponent(options: {
database: IPgComponent
favoritesComponent: IFavoritesComponent
isFavoritesEnabled: boolean
}): ICatalogComponent {
const { database, favoritesComponent, isFavoritesEnabled } = options
const { database, favoritesComponent } = options

async function fetch(filters: CatalogOptions) {
const { network, creator } = filters
Expand Down Expand Up @@ -86,14 +85,12 @@ export function createCatalogComponent(options: {
)
total = results.rows[0]?.total ?? results.rows[0]?.total_rows ?? 0

if (isFavoritesEnabled) {
const picksStats = await favoritesComponent.getPicksStatsOfItems(
catalogItems.map(({ id }) => id),
filters.pickedBy
)
const picksStats = await favoritesComponent.getPicksStatsOfItems(
catalogItems.map(({ id }) => id),
filters.pickedBy
)

catalogItems = enhanceItemsWithPicksStats(catalogItems, picksStats)
}
catalogItems = enhanceItemsWithPicksStats(catalogItems, picksStats)
} catch (e) {
console.error(e)
throw new HttpError(
Expand Down
105 changes: 30 additions & 75 deletions src/tests/adapters/sources/item-source.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ let components: {
favoritesComponent: IFavoritesComponent
}
let itemSource: IMergerComponent.Source<Item, ItemOptions, ItemSortBy>
let options: {
isFavoritesEnabled?: boolean
}
let fetchMock: jest.Mock
let countMock: jest.Mock
let getPicksStatsOfItemsMock: jest.Mock
Expand All @@ -38,12 +35,37 @@ beforeEach(() => {
favoritesComponent: favoritesComponentMock,
}

itemSource = createItemsSource(components, options)
itemSource = createItemsSource(components)
})

describe('when fetching items', () => {
let items: Item[]
let result: Sortable<Item, ItemSortBy>[]
let picksStats: PickStats[]
let pickedBy: string

beforeEach(() => {
itemSource = createItemsSource(components)

items = Array.from(
{ length: 2 },
(_, i) =>
({
id: `0x0-${i.toString()}`,
name: `item-name-${i}`,
contractAddress: '0x0',
itemId: i.toString(),
} as Item)
)
picksStats = items.map(
(item, i) =>
({
itemId: item.id,
pickedByUser: i > 0,
count: i,
} as PickStats)
)
})

describe('and fetching the items fails', () => {
beforeEach(() => {
Expand All @@ -57,64 +79,8 @@ describe('when fetching items', () => {
})
})

describe('and the favorites feature is disabled', () => {
beforeEach(async () => {
options = {
isFavoritesEnabled: false,
}
itemSource = createItemsSource(components, options)

items = Array.from(
{ length: 2 },
(_, i) =>
({
id: `0x0-${i.toString()}`,
name: `item-name-${i}`,
contractAddress: '0x0',
itemId: i.toString(),
} as Item)
)
fetchMock.mockResolvedValueOnce(items)
result = await itemSource.fetch({})
})

it('should resolve to a list of items without enhancing them with their picks stats', () => {
expect(result).toEqual(items.map(convertItemToSortableResult))
})

it('should not have queried the picks stats', () => {
expect(getPicksStatsOfItemsMock).not.toHaveBeenCalled()
})
})

describe('and the favorites feature is enabled', () => {
let picksStats: PickStats[]
let pickedBy: string

beforeEach(async () => {
options = {
isFavoritesEnabled: true,
}
itemSource = createItemsSource(components, options)

items = Array.from(
{ length: 2 },
(_, i) =>
({
id: `0x0-${i.toString()}`,
name: `item-name-${i}`,
contractAddress: '0x0',
itemId: i.toString(),
} as Item)
)
picksStats = items.map(
(item, i) =>
({
itemId: item.id,
pickedByUser: i > 0,
count: i,
} as PickStats)
)
describe('and fetching the items does not fail', () => {
beforeEach(() => {
fetchMock.mockResolvedValueOnce(items)
})

Expand Down Expand Up @@ -190,20 +156,9 @@ describe('when fetching items', () => {
})

describe('when counting items', () => {
describe('and the favorites feature is disabled', () => {
beforeEach(() => {
itemSource = createItemsSource(components, { isFavoritesEnabled: false })
countMock.mockResolvedValueOnce(15)
})

it('should resolve to the number of items', () => {
return expect(itemSource.count({})).resolves.toBe(15)
})
})

describe('and the favorites feature is enabled', () => {
describe('and the fetching the count of items succeeds', () => {
beforeEach(() => {
itemSource = createItemsSource(components, { isFavoritesEnabled: true })
itemSource = createItemsSource(components)
countMock.mockResolvedValueOnce(10)
})

Expand Down
27 changes: 9 additions & 18 deletions src/tests/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,6 @@ export async function initComponents(): Promise<AppComponents> {
const collectionsChainId = getCollectionsChainId()
const signaturesServer = await config.requireString('SIGNATURES_SERVER_URL')

const isFavoritesEnabled = (await config.getNumber('FF_FAVORITES')) === 1

const cors = {
origin: await config.getString('CORS_ORIGIN'),
method: await config.getString('CORS_METHOD'),
Expand Down Expand Up @@ -387,13 +385,10 @@ export async function initComponents(): Promise<AppComponents> {

const items = createMergerComponent<Item, ItemFilters, ItemSortBy>({
sources: [
createItemsSource(
{
itemsComponent: collectionsItems,
favoritesComponent,
},
{ isFavoritesEnabled }
),
createItemsSource({
itemsComponent: collectionsItems,
favoritesComponent,
}),
],
defaultSortBy: ITEM_DEFAULT_SORT_BY,
directions: {
Expand Down Expand Up @@ -451,14 +446,11 @@ export async function initComponents(): Promise<AppComponents> {
})

// trendings
const trendings = createTrendingsComponent(
{
collectionsSubgraphComponent: collectionsSubgraph,
itemsComponent: items,
favoritesComponent,
},
{ isFavoritesEnabled }
)
const trendings = createTrendingsComponent({
collectionsSubgraphComponent: collectionsSubgraph,
itemsComponent: items,
favoritesComponent,
})

// analytics day data for the marketplace subgraph
const marketplaceAnalyticsDayData = createAnalyticsDayDataComponent({
Expand Down Expand Up @@ -626,7 +618,6 @@ export async function initComponents(): Promise<AppComponents> {
const catalog = await createCatalogComponent({
database: satsumaDatabase,
favoritesComponent,
isFavoritesEnabled,
})

return {
Expand Down
1 change: 0 additions & 1 deletion src/tests/ports/catalog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ test('catalog component', function () {
catalogComponent = createCatalogComponent({
database,
favoritesComponent: favoritesComponentMock,
isFavoritesEnabled: true,
})
})

Expand Down