import { PostgreSQL } from "./types";
const { one_result } = require("../postgres-base");
import { callback } from "awaiting";
import { reuseInFlight } from "@cocalc/util/reuse-in-flight";
async function _get_remember_me(
db: PostgreSQL,
hash: string,
cache: boolean
): Promise<string | undefined> {
function f(cb: Function): void {
db._query({
cache,
query: "SELECT account_id, expire FROM remember_me",
where: {
"hash = $::CHAR(127)": hash.slice(0, 127),
},
retry_until_success: { max_time: 60000, start_delay: 10000 },
cb: one_result("account_id", cb),
});
}
return await callback(f);
}
export const get_remember_me = reuseInFlight(_get_remember_me, {
createKey: function (args) {
return args[1] + args[2];
},
});