mirror of
https://github.com/immich-app/immich.git
synced 2026-03-01 18:19:10 +03:00
refactor: use new updateId column for user CUD sync (#16384)
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Insertable, Kysely, sql } from 'kysely';
|
||||
import { InjectKysely } from 'nestjs-kysely';
|
||||
import { columns } from 'src/database';
|
||||
import { DB, SessionSyncCheckpoints } from 'src/db';
|
||||
import { SyncEntityType } from 'src/enum';
|
||||
import { SyncAck } from 'src/types';
|
||||
@@ -41,39 +40,19 @@ export class SyncRepository {
|
||||
getUserUpserts(ack?: SyncAck) {
|
||||
return this.db
|
||||
.selectFrom('users')
|
||||
.select(['id', 'name', 'email', 'deletedAt'])
|
||||
.select(columns.ackEpoch('updatedAt'))
|
||||
.$if(!!ack, (qb) =>
|
||||
qb.where((eb) =>
|
||||
eb.or([
|
||||
eb(eb.fn<Date>('to_timestamp', [sql.val(ack!.ackEpoch)]), '<', eb.ref('updatedAt')),
|
||||
eb.and([
|
||||
eb(eb.fn<Date>('to_timestamp', [sql.val(ack!.ackEpoch)]), '<=', eb.ref('updatedAt')),
|
||||
eb('id', '>', ack!.ids[0]),
|
||||
]),
|
||||
]),
|
||||
),
|
||||
)
|
||||
.orderBy(['updatedAt asc', 'id asc'])
|
||||
.select(['id', 'name', 'email', 'deletedAt', 'updateId'])
|
||||
.$if(!!ack, (qb) => qb.where('updateId', '>', ack!.updateId))
|
||||
.where('updatedAt', '<', sql.raw<Date>("now() - interval '1 millisecond'"))
|
||||
.orderBy(['updateId asc'])
|
||||
.stream();
|
||||
}
|
||||
|
||||
getUserDeletes(ack?: SyncAck) {
|
||||
return this.db
|
||||
.selectFrom('users_audit')
|
||||
.select(['userId'])
|
||||
.select(columns.ackEpoch('deletedAt'))
|
||||
.$if(!!ack, (qb) =>
|
||||
qb.where((eb) =>
|
||||
eb.or([
|
||||
eb(eb.fn<Date>('to_timestamp', [sql.val(ack!.ackEpoch)]), '<', eb.ref('deletedAt')),
|
||||
eb.and([
|
||||
eb(eb.fn<Date>('to_timestamp', [sql.val(ack!.ackEpoch)]), '<=', eb.ref('deletedAt')),
|
||||
eb('userId', '>', ack!.ids[0]),
|
||||
]),
|
||||
]),
|
||||
),
|
||||
)
|
||||
.select(['id', 'userId'])
|
||||
.$if(!!ack, (qb) => qb.where('id', '>', ack!.updateId))
|
||||
.where('deletedAt', '<', sql.raw<Date>("now() - interval '1 millisecond'"))
|
||||
.orderBy(['deletedAt asc', 'userId asc'])
|
||||
.stream();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user