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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add personalized following k3l algo #3507

Merged
merged 1 commit into from
Aug 11, 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: 1 addition & 1 deletion packages/data/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: { globals: true }
test: { globals: true, testTimeout: 30000 }
});
2 changes: 1 addition & 1 deletion packages/lens/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: { globals: true }
test: { globals: true, testTimeout: 30000 }
});
2 changes: 1 addition & 1 deletion packages/lib/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: { globals: true }
test: { globals: true, testTimeout: 30000 }
});
2 changes: 1 addition & 1 deletion packages/workers/ens/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: { globals: true }
test: { globals: true, testTimeout: 30000 }
});
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,13 @@ describe('getPublicationIds', () => {
const response: Response = await getRequest.json();
expect(response.ids.length).toBe(50);
});

test('should return ids for k3l provider, following strategy and profile', async () => {
const getRequest = await fetch(
`${TEST_URL}/ids?provider=k3l&strategy=following&profile=yoginth.lens`
);
const response: Response = await getRequest.json();
expect(response.ids.length).toBe(50);
});
});
});
3 changes: 2 additions & 1 deletion packages/workers/feeds/src/handlers/getPublicationIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { Env } from '../types';
export default async (request: IRequest, env: Env) => {
const provider = request.query.provider as string;
const strategy = request.query.strategy as string;
const profile = request.query.profile as string;
const limit = (parseInt(request.query?.limit as string) || 50) as number;
const offset = (parseInt(request.query?.offset as string) || 0) as number;

Expand All @@ -24,7 +25,7 @@ export default async (request: IRequest, env: Env) => {
let ids: string[] = [];
switch (provider) {
case AlgorithmProvider.K3L:
ids = await k3lFeed(strategy, limit, offset);
ids = await k3lFeed(strategy, profile, limit, offset);
break;
case AlgorithmProvider.LENSTER:
ids = await lensterFeed(strategy, limit, offset, env);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import randomizeIds from '../../../helpers/randomizeIds';

const k3lGlobalFeed = async (
strategy: string,
limit: number,
offset: number
) => {
try {
const response = await fetch(
`https://lens-api.k3l.io/feed/${strategy}?limit=${limit}&offset=${offset}`,
{ headers: { 'User-Agent': 'Lenster' } }
);
const json: {
postId: string;
}[] = await response.json();
const ids = json.map((item: any) => item.postId);

return randomizeIds(ids);
} catch (error) {
console.log(error);
return [];
}
};

export default k3lGlobalFeed;
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import randomizeIds from '../../../helpers/randomizeIds';

const k3lPersonalFeed = async (
strategy: string,
profile: string,
limit: number,
offset: number
) => {
try {
const response = await fetch(
`https://lens-api.k3l.io/feed/personal/${profile}/${strategy}?limit=${limit}&offset=${offset}`,
{ headers: { 'User-Agent': 'Lenster' } }
);
const json: {
postId: string;
}[] = await response.json();
const ids = json.map((item: any) => item.postId);

return randomizeIds(ids);
} catch (error) {
console.log(error);
return [];
}
};

export default k3lPersonalFeed;
28 changes: 12 additions & 16 deletions packages/workers/feeds/src/providers/k3l/k3lFeed.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import randomizeIds from '../../helpers/randomizeIds';
import k3lGlobalFeed from './algorithms/k3lGlobalFeed';
import k3lPersonalFeed from './algorithms/k3lPersonalFeed';

const k3lFeed = async (strategy: string, limit: number, offset: number) => {
try {
const response = await fetch(
`https://lens-api.k3l.io/feed/${strategy}?limit=${limit}&offset=${offset}`,
{ headers: { 'User-Agent': 'Lenster' } }
);
const json: {
postId: string;
}[] = await response.json();
const ids = json.map((item: any) => item.postId);

return randomizeIds(ids);
} catch (error) {
console.log(error);
return [];
const k3lFeed = async (
strategy: string,
profile: string,
limit: number,
offset: number
) => {
if (profile) {
return await k3lPersonalFeed(strategy, profile, limit, offset);
}

return await k3lGlobalFeed(strategy, limit, offset);
};

export default k3lFeed;
2 changes: 1 addition & 1 deletion packages/workers/feeds/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: { globals: true }
test: { globals: true, testTimeout: 30000 }
});
2 changes: 1 addition & 1 deletion packages/workers/ipfs/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: { globals: true }
test: { globals: true, testTimeout: 30000 }
});
2 changes: 1 addition & 1 deletion packages/workers/metadata/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: { globals: true }
test: { globals: true, testTimeout: 30000 }
});
2 changes: 1 addition & 1 deletion packages/workers/oembed/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: { globals: true }
test: { globals: true, testTimeout: 30000 }
});
Loading