data & perftest
This commit is contained in:
@@ -4,7 +4,8 @@ import {
|
||||
CommercialPropertyListing,
|
||||
ListingCriteria,
|
||||
ListingType,
|
||||
ImageProperty
|
||||
ImageProperty,
|
||||
ListingCategory
|
||||
} from '../models/main.model.js';
|
||||
import { convertStringToNullUndefined } from '../utils.js';
|
||||
import { WINSTON_MODULE_PROVIDER } from 'nest-winston';
|
||||
@@ -14,6 +15,8 @@ import { REDIS_CLIENT } from '../redis/redis.module.js';
|
||||
|
||||
@Injectable()
|
||||
export class ListingsService {
|
||||
schemaNameBusiness:ListingCategory={name:'business'}
|
||||
schemaNameCommercial:ListingCategory={name:'commercialProperty'}
|
||||
businessListingRepository:Repository;
|
||||
commercialPropertyListingRepository:Repository;
|
||||
baseListingSchemaDef : SchemaDefinition = {
|
||||
@@ -53,13 +56,13 @@ export class ListingsService {
|
||||
...this.baseListingSchemaDef,
|
||||
imageNames:{ type: 'string[]' },
|
||||
}
|
||||
businessListingSchema = new Schema('businessListing',this.businessListingSchemaDef, {
|
||||
businessListingSchema = new Schema(this.schemaNameBusiness.name,this.businessListingSchemaDef, {
|
||||
dataStructure: 'JSON'
|
||||
})
|
||||
commercialPropertyListingSchema = new Schema('commercialPropertyListing',this.commercialPropertyListingSchemaDef, {
|
||||
commercialPropertyListingSchema = new Schema(this.schemaNameCommercial.name,this.commercialPropertyListingSchemaDef, {
|
||||
dataStructure: 'JSON'
|
||||
})
|
||||
constructor(@Inject(REDIS_CLIENT) private readonly redis: any){
|
||||
constructor(@Inject(REDIS_CLIENT) private readonly redis: any, @Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger){
|
||||
this.businessListingRepository = new Repository(this.businessListingSchema, redis);
|
||||
this.commercialPropertyListingRepository = new Repository(this.commercialPropertyListingSchema, redis)
|
||||
this.businessListingRepository.createIndex();
|
||||
@@ -99,13 +102,40 @@ export class ListingsService {
|
||||
return await this.commercialPropertyListingRepository.search().return.all()
|
||||
}
|
||||
async findBusinessListings(criteria:ListingCriteria): Promise<any> {
|
||||
let listings = await this.getAllBusinessListings();
|
||||
return this.find(criteria,listings);
|
||||
// let listings = await this.getAllBusinessListings();
|
||||
// return this.find(criteria,listings);
|
||||
this.logger.info(`start findBusinessListings: ${JSON.stringify(criteria)}`);
|
||||
const result = await this.redis.ft.search('business:index','*',{LIMIT:{from:0,size:50}});
|
||||
this.logger.info(`start findBusinessListings: ${JSON.stringify(criteria)}`);
|
||||
return result.documents;
|
||||
}
|
||||
async findCommercialPropertyListings(criteria:ListingCriteria): Promise<any> {
|
||||
let listings = await this.getAllCommercialListings();
|
||||
return this.find(criteria,listings);
|
||||
}
|
||||
async deleteAllBusinessListings(){
|
||||
const ids = await this.getIdsForRepo(this.schemaNameBusiness.name);
|
||||
this.businessListingRepository.remove(ids);
|
||||
}
|
||||
async deleteAllcommercialListings(){
|
||||
const ids = await this.getIdsForRepo(this.schemaNameCommercial.name);
|
||||
this.commercialPropertyListingRepository.remove(ids);
|
||||
}
|
||||
async getIdsForRepo(repoName:string, maxcount=100000){
|
||||
let cursor = 0;
|
||||
let ids = [];
|
||||
do {
|
||||
const reply = await this.redis.scan(cursor, {
|
||||
MATCH: `${repoName}:*`,
|
||||
COUNT: maxcount
|
||||
});
|
||||
cursor = reply.cursor;
|
||||
// Extrahiere die ID aus jedem Schlüssel und füge sie zur Liste hinzu
|
||||
ids = ids.concat(reply.keys.map(key => key.split(':')[1]).filter(id=>id!='index'));
|
||||
} while (cursor !== 0);
|
||||
return ids;
|
||||
}
|
||||
|
||||
async find(criteria:ListingCriteria, listings: any[]): Promise<any> {
|
||||
listings=listings.filter(l=>l.listingsCategory===criteria.listingsCategory);
|
||||
if (convertStringToNullUndefined(criteria.type)){
|
||||
|
||||
Reference in New Issue
Block a user