formattin~
This commit is contained in:
parent
f1c18e0b09
commit
c9c183fec0
1 changed files with 22 additions and 20 deletions
|
@ -1,4 +1,4 @@
|
||||||
import {FindManyOptions, In} from "typeorm";
|
import { FindManyOptions, In } from "typeorm";
|
||||||
import { Notes } from "@/models/index.js";
|
import { Notes } from "@/models/index.js";
|
||||||
import { Note } from "@/models/entities/note.js";
|
import { Note } from "@/models/entities/note.js";
|
||||||
import config from "@/config/index.js";
|
import config from "@/config/index.js";
|
||||||
|
@ -180,9 +180,9 @@ export default define(meta, paramDef, async (ps, me) => {
|
||||||
const sortByDate = ps.order !== "relevancy";
|
const sortByDate = ps.order !== "relevancy";
|
||||||
|
|
||||||
type NoteResult = {
|
type NoteResult = {
|
||||||
id: string,
|
id: string;
|
||||||
createdAt: number
|
createdAt: number;
|
||||||
}
|
};
|
||||||
const extractedNotes: NoteResult[] = [];
|
const extractedNotes: NoteResult[] = [];
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -221,8 +221,8 @@ export default define(meta, paramDef, async (ps, me) => {
|
||||||
.map((key) => {
|
.map((key) => {
|
||||||
return {
|
return {
|
||||||
id: key.id,
|
id: key.id,
|
||||||
createdAt: key.createdAt
|
createdAt: key.createdAt,
|
||||||
}
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
extractedNotes.push(...res);
|
extractedNotes.push(...res);
|
||||||
|
@ -238,7 +238,7 @@ export default define(meta, paramDef, async (ps, me) => {
|
||||||
// Fetch the notes from the database until we have enough to satisfy the limit
|
// Fetch the notes from the database until we have enough to satisfy the limit
|
||||||
start = 0;
|
start = 0;
|
||||||
const found = [];
|
const found = [];
|
||||||
const noteIDs = extractedNotes.map(note => note.id);
|
const noteIDs = extractedNotes.map((note) => note.id);
|
||||||
|
|
||||||
// Index the ID => index number into a map, so we can sort efficiently later
|
// Index the ID => index number into a map, so we can sort efficiently later
|
||||||
const idIndexMap = new Map(noteIDs.map((id, index) => [id, index]));
|
const idIndexMap = new Map(noteIDs.map((id, index) => [id, index]));
|
||||||
|
@ -246,20 +246,22 @@ export default define(meta, paramDef, async (ps, me) => {
|
||||||
while (found.length < ps.limit && start < noteIDs.length) {
|
while (found.length < ps.limit && start < noteIDs.length) {
|
||||||
const chunk = noteIDs.slice(start, start + chunkSize);
|
const chunk = noteIDs.slice(start, start + chunkSize);
|
||||||
|
|
||||||
let query : FindManyOptions = sortByDate ? {
|
let query: FindManyOptions = sortByDate
|
||||||
where: {
|
? {
|
||||||
id: In(chunk),
|
where: {
|
||||||
},
|
id: In(chunk),
|
||||||
order: {
|
},
|
||||||
id: "DESC"
|
order: {
|
||||||
}
|
id: "DESC",
|
||||||
} : {
|
},
|
||||||
where: {
|
}
|
||||||
id: In(chunk),
|
: {
|
||||||
},
|
where: {
|
||||||
}
|
id: In(chunk),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
console.log(JSON.stringify(query))
|
console.log(JSON.stringify(query));
|
||||||
|
|
||||||
const notes: Note[] = await Notes.find(query);
|
const notes: Note[] = await Notes.find(query);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue