mirror of
https://github.com/KevinMidboe/immich.git
synced 2025-10-29 17:40:28 +00:00
refactor(server,web): time buckets for main timeline, archived, and favorites (1) (#3537)
* refactor: time buckets * feat(web): use new time bucket api * feat(web): use asset grid in archive/favorites * chore: open api * chore: clean up uuid validation * refactor(web): move memory lane to photos page * Update web/src/routes/(user)/archive/+page.svelte Co-authored-by: Sergey Kondrikov <sergey.kondrikov@gmail.com> * fix: hide archived photos on main timeline * fix: select exif info --------- Co-authored-by: Sergey Kondrikov <sergey.kondrikov@gmail.com>
This commit is contained in:
@@ -8,6 +8,9 @@ import {
|
||||
MapMarkerSearchOptions,
|
||||
Paginated,
|
||||
PaginationOptions,
|
||||
TimeBucketItem,
|
||||
TimeBucketOptions,
|
||||
TimeBucketSize,
|
||||
WithoutProperty,
|
||||
WithProperty,
|
||||
} from '@app/domain';
|
||||
@@ -19,6 +22,11 @@ import { AssetEntity, AssetType } from '../entities';
|
||||
import OptionalBetween from '../utils/optional-between.util';
|
||||
import { paginate } from '../utils/pagination.util';
|
||||
|
||||
const truncateMap: Record<TimeBucketSize, string> = {
|
||||
[TimeBucketSize.DAY]: 'day',
|
||||
[TimeBucketSize.MONTH]: 'month',
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
export class AssetRepository implements IAssetRepository {
|
||||
constructor(@InjectRepository(AssetEntity) private repository: Repository<AssetEntity>) {}
|
||||
@@ -357,4 +365,47 @@ export class AssetRepository implements IAssetRepository {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
getTimeBuckets(userId: string, options: TimeBucketOptions): Promise<TimeBucketItem[]> {
|
||||
const truncateValue = truncateMap[options.size];
|
||||
|
||||
return this.getBuilder(userId, options)
|
||||
.select(`COUNT(asset.id)::int`, 'count')
|
||||
.addSelect(`date_trunc('${truncateValue}', "fileCreatedAt")`, 'timeBucket')
|
||||
.groupBy(`date_trunc('${truncateValue}', "fileCreatedAt")`)
|
||||
.orderBy(`date_trunc('${truncateValue}', "fileCreatedAt")`, 'DESC')
|
||||
.getRawMany();
|
||||
}
|
||||
|
||||
getByTimeBucket(userId: string, timeBucket: string, options: TimeBucketOptions): Promise<AssetEntity[]> {
|
||||
const truncateValue = truncateMap[options.size];
|
||||
return this.getBuilder(userId, options)
|
||||
.andWhere(`date_trunc('${truncateValue}', "fileCreatedAt") = :timeBucket`, { timeBucket })
|
||||
.orderBy('asset.fileCreatedAt', 'DESC')
|
||||
.getMany();
|
||||
}
|
||||
|
||||
private getBuilder(userId: string, options: TimeBucketOptions) {
|
||||
const { isArchived, isFavorite, albumId } = options;
|
||||
|
||||
let builder = this.repository
|
||||
.createQueryBuilder('asset')
|
||||
.where('asset.ownerId = :userId', { userId })
|
||||
.andWhere('asset.isVisible = true')
|
||||
.leftJoinAndSelect('asset.exifInfo', 'exifInfo');
|
||||
|
||||
if (albumId) {
|
||||
builder = builder.leftJoin('asset.albums', 'album').andWhere('album.id = :albumId', { albumId });
|
||||
}
|
||||
|
||||
if (isArchived != undefined) {
|
||||
builder = builder.andWhere('asset.isArchived = :isArchived', { isArchived });
|
||||
}
|
||||
|
||||
if (isFavorite !== undefined) {
|
||||
builder = builder.andWhere('asset.isFavorite = :isFavorite', { isFavorite });
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user