Removed commented code from project Cache

This commit is contained in:
ashutosh.nehete 2025-07-17 17:16:16 +05:30
parent c8978ee9b1
commit b71935dd1f
2 changed files with 10 additions and 41 deletions

View File

@ -23,6 +23,8 @@ namespace Marco.Pms.CacheHelper
_taskCollection = mongoDB.GetCollection<WorkItemMongoDB>("WorkItemDetails"); _taskCollection = mongoDB.GetCollection<WorkItemMongoDB>("WorkItemDetails");
} }
#region=================================================================== Project Cache Helper ===================================================================
public async Task AddProjectDetailsToCache(ProjectMongoDB projectDetails) public async Task AddProjectDetailsToCache(ProjectMongoDB projectDetails)
{ {
await _projectCollection.InsertOneAsync(projectDetails); await _projectCollection.InsertOneAsync(projectDetails);
@ -36,7 +38,6 @@ namespace Marco.Pms.CacheHelper
await _projectCollection.Indexes.CreateOneAsync(indexModel); await _projectCollection.Indexes.CreateOneAsync(indexModel);
} }
// The method should focus only on inserting data.
public async Task AddProjectDetailsListToCache(List<ProjectMongoDB> projectDetailsList) public async Task AddProjectDetailsListToCache(List<ProjectMongoDB> projectDetailsList)
{ {
// 1. Add a guard clause to avoid an unnecessary database call for an empty list. // 1. Add a guard clause to avoid an unnecessary database call for an empty list.
@ -49,7 +50,6 @@ namespace Marco.Pms.CacheHelper
await _projectCollection.InsertManyAsync(projectDetailsList); await _projectCollection.InsertManyAsync(projectDetailsList);
await InitializeCollectionAsync(); await InitializeCollectionAsync();
} }
// A private method to handle the one-time setup of the collection's indexes.
private async Task InitializeCollectionAsync() private async Task InitializeCollectionAsync()
{ {
// 1. Define the TTL (Time-To-Live) index on the 'ExpireAt' field. // 1. Define the TTL (Time-To-Live) index on the 'ExpireAt' field.
@ -135,7 +135,9 @@ namespace Marco.Pms.CacheHelper
return result.DeletedCount > 0; return result.DeletedCount > 0;
} }
// ------------------------------------------------------- Project InfraStructure ------------------------------------------------------- #endregion
#region=================================================================== Project infrastructure Cache Helper ===================================================================
public async Task AddBuildngInfraToCache(Guid projectId, Building? building, Floor? floor, WorkArea? workArea, Guid? buildingId) public async Task AddBuildngInfraToCache(Guid projectId, Building? building, Floor? floor, WorkArea? workArea, Guid? buildingId)
{ {
@ -161,11 +163,8 @@ namespace Marco.Pms.CacheHelper
if (result.MatchedCount == 0) if (result.MatchedCount == 0)
{ {
//_logger.LogWarning("Project not found while adding building. ProjectId: {ProjectId}", projectId);
return; return;
} }
//_logger.LogInfo("Building {BuildingId} added to project {ProjectId}", building.Id, projectId);
return; return;
} }
@ -191,11 +190,8 @@ namespace Marco.Pms.CacheHelper
if (result.MatchedCount == 0) if (result.MatchedCount == 0)
{ {
//_logger.LogWarning("Project or building not found while adding floor. ProjectId: {ProjectId}, BuildingId: {BuildingId}", projectId, floor.BuildingId);
return; return;
} }
//_logger.LogInfo("Floor {FloorId} added to building {BuildingId} in project {ProjectId}", floor.Id, floor.BuildingId, projectId);
return; return;
} }
@ -225,16 +221,10 @@ namespace Marco.Pms.CacheHelper
if (result.MatchedCount == 0) if (result.MatchedCount == 0)
{ {
//_logger.LogWarning("Project or nested structure not found while adding work area. ProjectId: {ProjectId}, BuildingId: {BuildingId}, FloorId: {FloorId}", projectId, buildingId, workArea.FloorId);
return; return;
} }
//_logger.LogInfo("WorkArea {WorkAreaId} added to floor {FloorId} in building {BuildingId}, ProjectId: {ProjectId}", workArea.Id, workArea.FloorId, buildingId, projectId);
return; return;
} }
// Fallback case when no valid data was passed
//_logger.LogWarning("No valid infra data provided to add for ProjectId: {ProjectId}", projectId);
} }
public async Task<bool> UpdateBuildngInfraToCache(Guid projectId, Building? building, Floor? floor, WorkArea? workArea, Guid? buildingId) public async Task<bool> UpdateBuildngInfraToCache(Guid projectId, Building? building, Floor? floor, WorkArea? workArea, Guid? buildingId)
{ {
@ -257,11 +247,9 @@ namespace Marco.Pms.CacheHelper
if (result.MatchedCount == 0) if (result.MatchedCount == 0)
{ {
//_logger.LogWarning("Update failed: Project or Building not found. ProjectId: {ProjectId}, BuildingId: {BuildingId}", projectId, building.Id);
return false; return false;
} }
//_logger.LogInfo("Building {BuildingId} updated successfully in project {ProjectId}", building.Id, projectId);
return true; return true;
} }
@ -282,11 +270,8 @@ namespace Marco.Pms.CacheHelper
if (result.MatchedCount == 0) if (result.MatchedCount == 0)
{ {
//_logger.LogWarning("Update failed: Project or Floor not found. ProjectId: {ProjectId}, BuildingId: {BuildingId}, FloorId: {FloorId}", projectId, floor.BuildingId, floor.Id);
return false; return false;
} }
//_logger.LogInfo("Floor {FloorId} updated successfully in Building {BuildingId}, ProjectId: {ProjectId}", floor.Id, floor.BuildingId, projectId);
return true; return true;
} }
@ -308,17 +293,10 @@ namespace Marco.Pms.CacheHelper
if (result.MatchedCount == 0) if (result.MatchedCount == 0)
{ {
//_logger.LogWarning("Update failed: Project or WorkArea not found. ProjectId: {ProjectId}, BuildingId: {BuildingId}, FloorId: {FloorId}, WorkAreaId: {WorkAreaId}",
//projectId, buildingId, workArea.FloorId, workArea.Id);
return false; return false;
} }
//_logger.LogInfo("WorkArea {WorkAreaId} updated successfully in Floor {FloorId}, Building {BuildingId}, ProjectId: {ProjectId}",
//workArea.Id, workArea.FloorId, buildingId, projectId);
return true; return true;
} }
//_logger.LogWarning("No update performed. Missing or invalid data for ProjectId: {ProjectId}", projectId);
return false; return false;
} }
public async Task<List<BuildingMongoDB>?> GetBuildingInfraFromCache(Guid projectId) public async Task<List<BuildingMongoDB>?> GetBuildingInfraFromCache(Guid projectId)
@ -333,15 +311,6 @@ namespace Marco.Pms.CacheHelper
.Project(p => p.Buildings) .Project(p => p.Buildings)
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
//if (buildings == null)
//{
// _logger.LogWarning("No building infrastructure found for ProjectId: {ProjectId}", projectId);
//}
//else
//{
// _logger.LogInfo("Fetched {Count} buildings for ProjectId: {ProjectId}", buildings.Count, projectId);
//}
return buildings; return buildings;
} }
public async Task UpdatePlannedAndCompleteWorksInBuildingFromCache(Guid workAreaId, double plannedWork, double completedWork) public async Task UpdatePlannedAndCompleteWorksInBuildingFromCache(Guid workAreaId, double plannedWork, double completedWork)
@ -431,8 +400,9 @@ namespace Marco.Pms.CacheHelper
return result; return result;
} }
#endregion
// ------------------------------------------------------- WorkItem ------------------------------------------------------- #region=================================================================== WorkItem Cache Helper ===================================================================
public async Task<List<WorkItemMongoDB>> GetWorkItemsByWorkAreaIdsFromCache(List<Guid> workAreaIds) public async Task<List<WorkItemMongoDB>> GetWorkItemsByWorkAreaIdsFromCache(List<Guid> workAreaIds)
{ {
@ -517,5 +487,7 @@ namespace Marco.Pms.CacheHelper
var result = await _taskCollection.DeleteOneAsync(filter); var result = await _taskCollection.DeleteOneAsync(filter);
return result.DeletedCount > 0; return result.DeletedCount > 0;
} }
#endregion
} }
} }

View File

@ -1,4 +1,3 @@
using Marco.Pms.DataAccess.Data;
using Marco.Pms.Model.MongoDBModels; using Marco.Pms.Model.MongoDBModels;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using MongoDB.Driver; using MongoDB.Driver;
@ -7,12 +6,10 @@ namespace Marco.Pms.CacheHelper
{ {
public class ReportCache public class ReportCache
{ {
private readonly ApplicationDbContext _context;
private readonly IMongoCollection<ProjectReportEmailMongoDB> _projectReportCollection; private readonly IMongoCollection<ProjectReportEmailMongoDB> _projectReportCollection;
public ReportCache(ApplicationDbContext context, IConfiguration configuration) public ReportCache(IConfiguration configuration)
{ {
var connectionString = configuration["MongoDB:ConnectionString"]; var connectionString = configuration["MongoDB:ConnectionString"];
_context = context;
var mongoUrl = new MongoUrl(connectionString); var mongoUrl = new MongoUrl(connectionString);
var client = new MongoClient(mongoUrl); // Your MongoDB connection string var client = new MongoClient(mongoUrl); // Your MongoDB connection string
var mongoDB = client.GetDatabase(mongoUrl.DatabaseName); // Your MongoDB Database name var mongoDB = client.GetDatabase(mongoUrl.DatabaseName); // Your MongoDB Database name