Skip to content

Commit

Permalink
feat: add personalized following k3l algo
Browse files Browse the repository at this point in the history
  • Loading branch information
bigint committed Aug 11, 2023
1 parent f238b4c commit db12a09
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 25 deletions.
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 }
});
8 changes: 8 additions & 0 deletions packages/workers/feeds/src/handlers/getPublicationIds.spec.ts
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 }
});

0 comments on commit db12a09

Please sign in to comment.