[questions][fix] encounter last seen sorting (#530)

Co-authored-by: Jeff Sieu <jeffsy00@gmail.com>
pull/531/head
hpkoh 2 years ago committed by GitHub
parent f400af76af
commit 861303016f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -223,7 +223,7 @@ export default function ContributeQuestionForm({
createEncounterButtonText="Yes, this is my question" createEncounterButtonText="Yes, this is my question"
questionId={question.id} questionId={question.id}
roles={roleCounts} roles={roleCounts}
timestamp={question.seenAt} timestamp={question.lastSeenAt}
type={question.type} type={question.type}
onReceivedSubmit={async (data) => { onReceivedSubmit={async (data) => {
await addEncounterAsync({ await addEncounterAsync({

@ -210,7 +210,7 @@ export default function QuestionPage() {
questionId={question.id} questionId={question.id}
receivedCount={undefined} receivedCount={undefined}
roles={relabeledAggregatedEncounters?.roleCounts ?? {}} roles={relabeledAggregatedEncounters?.roleCounts ?? {}}
timestamp={question.seenAt} timestamp={question.lastSeenAt}
upvoteCount={question.numVotes} upvoteCount={question.numVotes}
onReceivedSubmit={async (data) => { onReceivedSubmit={async (data) => {
await addEncounterAsync({ await addEncounterAsync({

@ -558,9 +558,7 @@ export default function QuestionsBrowsePage() {
questionId={question.id} questionId={question.id}
receivedCount={question.receivedCount} receivedCount={question.receivedCount}
roles={roleCounts} roles={roleCounts}
timestamp={ timestamp={question.lastSeenAt}
question.aggregatedQuestionEncounters.latestSeenAt
}
type={question.type} type={question.type}
upvoteCount={question.numVotes} upvoteCount={question.numVotes}
/> />

@ -220,7 +220,7 @@ export default function ListPage() {
questionId={question.id} questionId={question.id}
receivedCount={question.receivedCount} receivedCount={question.receivedCount}
roles={roleCounts} roles={roleCounts}
timestamp={question.seenAt} timestamp={question.lastSeenAt}
type={question.type} type={question.type}
onDelete={() => { onDelete={() => {
deleteQuestionEntry({ id: entryId }); deleteQuestionEntry({ id: entryId });

@ -39,7 +39,7 @@ export const questionsQuestionRouter = createRouter()
{ {
id: input.sortOrder, id: input.sortOrder,
}, },
] ];
break; break;
case SortType.NEW: case SortType.NEW:
sortCondition = [ sortCondition = [
@ -61,7 +61,7 @@ export const questionsQuestionRouter = createRouter()
}, },
]; ];
break; break;
} }
const questionsData = await ctx.prisma.questionsQuestion.findMany({ const questionsData = await ctx.prisma.questionsQuestion.findMany({
cursor: cursor ? { id: cursor } : undefined, cursor: cursor ? { id: cursor } : undefined,
@ -309,9 +309,8 @@ export const questionsQuestionRouter = createRouter()
let relatedQuestionsId: Array<{ id: string }> = []; let relatedQuestionsId: Array<{ id: string }> = [];
if (input.content !== "") { if (input.content !== '') {
relatedQuestionsId = await ctx.prisma relatedQuestionsId = await ctx.prisma.$queryRaw`
.$queryRaw`
SELECT id FROM "QuestionsQuestion" SELECT id FROM "QuestionsQuestion"
WHERE WHERE
ts_rank_cd(to_tsvector("content"), to_tsquery(${query}), 32) > 0.1 ts_rank_cd(to_tsvector("content"), to_tsquery(${query}), 32) > 0.1
@ -319,8 +318,6 @@ export const questionsQuestionRouter = createRouter()
`; `;
} }
const relatedQuestionsIdArray = relatedQuestionsId.map( const relatedQuestionsIdArray = relatedQuestionsId.map(
(current) => current.id, (current) => current.id,
); );
@ -338,7 +335,7 @@ export const questionsQuestionRouter = createRouter()
{ {
id: input.sortOrder, id: input.sortOrder,
}, },
] ];
break; break;
case SortType.NEW: case SortType.NEW:
sortCondition = [ sortCondition = [
@ -360,7 +357,7 @@ export const questionsQuestionRouter = createRouter()
}, },
]; ];
break; break;
} }
const questionsData = await ctx.prisma.questionsQuestion.findMany({ const questionsData = await ctx.prisma.questionsQuestion.findMany({
cursor: cursor ? { id: cursor } : undefined, cursor: cursor ? { id: cursor } : undefined,
@ -391,9 +388,12 @@ export const questionsQuestionRouter = createRouter()
orderBy: sortCondition, orderBy: sortCondition,
take: input.limit + 1, take: input.limit + 1,
where: { where: {
id: input.content !== "" ? { id:
in: relatedQuestionsIdArray, input.content !== ''
} : undefined, ? {
in: relatedQuestionsIdArray,
}
: undefined,
...(input.questionTypes.length > 0 ...(input.questionTypes.length > 0
? { ? {
questionType: { questionType: {

@ -4,11 +4,11 @@ export type Question = {
aggregatedQuestionEncounters: AggregatedQuestionEncounter; aggregatedQuestionEncounters: AggregatedQuestionEncounter;
content: string; content: string;
id: string; id: string;
lastSeenAt: Date | null;
numAnswers: number; numAnswers: number;
numComments: number; numComments: number;
numVotes: number; numVotes: number;
receivedCount: number; receivedCount: number;
seenAt: Date;
type: QuestionsQuestionType; type: QuestionsQuestionType;
updatedAt: Date; updatedAt: Date;
user: string; user: string;
@ -47,7 +47,6 @@ export type Location = CityLocation | CountryLocation | StateLocation;
export type AggregatedQuestionEncounter = { export type AggregatedQuestionEncounter = {
companyCounts: Record<string, number>; companyCounts: Record<string, number>;
countryCounts: Record<string, CountryInfo>; countryCounts: Record<string, CountryInfo>;
latestSeenAt: Date;
roleCounts: Record<string, number>; roleCounts: Record<string, number>;
}; };

@ -61,11 +61,11 @@ export function createQuestionWithAggregateData(
), ),
content: data.content, content: data.content,
id: data.id, id: data.id,
lastSeenAt: data.lastSeenAt,
numAnswers: data._count.answers, numAnswers: data._count.answers,
numComments: data._count.comments, numComments: data._count.comments,
numVotes: votes, numVotes: votes,
receivedCount: data.encounters.length, receivedCount: data.encounters.length,
seenAt: data.encounters[0].seenAt,
type: data.questionType, type: data.questionType,
updatedAt: data.updatedAt, updatedAt: data.updatedAt,
user: data.user?.name ?? '', user: data.user?.name ?? '',
@ -80,12 +80,7 @@ export function createAggregatedQuestionEncounter(
const companyCounts: Record<string, number> = {}; const companyCounts: Record<string, number> = {};
const roleCounts: Record<string, number> = {}; const roleCounts: Record<string, number> = {};
let latestSeenAt = encounters[0].seenAt;
for (const encounter of encounters) { for (const encounter of encounters) {
latestSeenAt =
latestSeenAt < encounter.seenAt ? encounter.seenAt : latestSeenAt;
if (encounter.company !== null) { if (encounter.company !== null) {
if (!(encounter.company.name in companyCounts)) { if (!(encounter.company.name in companyCounts)) {
companyCounts[encounter.company!.name] = 0; companyCounts[encounter.company!.name] = 0;
@ -137,7 +132,6 @@ export function createAggregatedQuestionEncounter(
return { return {
companyCounts, companyCounts,
countryCounts, countryCounts,
latestSeenAt,
roleCounts, roleCounts,
}; };
} }

Loading…
Cancel
Save