From 5e84ee9345c8a6db143cd4b456604bc9374e86ee Mon Sep 17 00:00:00 2001 From: "ashutosh.nehete" Date: Thu, 17 Jul 2025 17:16:16 +0530 Subject: [PATCH] Removed commented code from project Cache --- Marco.Pms.CacheHelper/ProjectCache.cs | 46 ++++++--------------------- Marco.Pms.CacheHelper/ReportCache.cs | 5 +-- 2 files changed, 10 insertions(+), 41 deletions(-) diff --git a/Marco.Pms.CacheHelper/ProjectCache.cs b/Marco.Pms.CacheHelper/ProjectCache.cs index df95419..a9ae3af 100644 --- a/Marco.Pms.CacheHelper/ProjectCache.cs +++ b/Marco.Pms.CacheHelper/ProjectCache.cs @@ -23,6 +23,8 @@ namespace Marco.Pms.CacheHelper _taskCollection = mongoDB.GetCollection("WorkItemDetails"); } + #region=================================================================== Project Cache Helper =================================================================== + public async Task AddProjectDetailsToCache(ProjectMongoDB projectDetails) { await _projectCollection.InsertOneAsync(projectDetails); @@ -36,7 +38,6 @@ namespace Marco.Pms.CacheHelper await _projectCollection.Indexes.CreateOneAsync(indexModel); } - // The method should focus only on inserting data. public async Task AddProjectDetailsListToCache(List projectDetailsList) { // 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 InitializeCollectionAsync(); } - // A private method to handle the one-time setup of the collection's indexes. private async Task InitializeCollectionAsync() { // 1. Define the TTL (Time-To-Live) index on the 'ExpireAt' field. @@ -135,7 +135,9 @@ namespace Marco.Pms.CacheHelper 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) { @@ -161,11 +163,8 @@ namespace Marco.Pms.CacheHelper if (result.MatchedCount == 0) { - //_logger.LogWarning("Project not found while adding building. ProjectId: {ProjectId}", projectId); return; } - - //_logger.LogInfo("Building {BuildingId} added to project {ProjectId}", building.Id, projectId); return; } @@ -191,11 +190,8 @@ namespace Marco.Pms.CacheHelper if (result.MatchedCount == 0) { - //_logger.LogWarning("Project or building not found while adding floor. ProjectId: {ProjectId}, BuildingId: {BuildingId}", projectId, floor.BuildingId); return; } - - //_logger.LogInfo("Floor {FloorId} added to building {BuildingId} in project {ProjectId}", floor.Id, floor.BuildingId, projectId); return; } @@ -225,16 +221,10 @@ namespace Marco.Pms.CacheHelper 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; } - - //_logger.LogInfo("WorkArea {WorkAreaId} added to floor {FloorId} in building {BuildingId}, ProjectId: {ProjectId}", workArea.Id, workArea.FloorId, buildingId, projectId); 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 UpdateBuildngInfraToCache(Guid projectId, Building? building, Floor? floor, WorkArea? workArea, Guid? buildingId) { @@ -257,11 +247,9 @@ namespace Marco.Pms.CacheHelper if (result.MatchedCount == 0) { - //_logger.LogWarning("Update failed: Project or Building not found. ProjectId: {ProjectId}, BuildingId: {BuildingId}", projectId, building.Id); return false; } - //_logger.LogInfo("Building {BuildingId} updated successfully in project {ProjectId}", building.Id, projectId); return true; } @@ -282,11 +270,8 @@ namespace Marco.Pms.CacheHelper 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; } - - //_logger.LogInfo("Floor {FloorId} updated successfully in Building {BuildingId}, ProjectId: {ProjectId}", floor.Id, floor.BuildingId, projectId); return true; } @@ -308,17 +293,10 @@ namespace Marco.Pms.CacheHelper 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; } - - //_logger.LogInfo("WorkArea {WorkAreaId} updated successfully in Floor {FloorId}, Building {BuildingId}, ProjectId: {ProjectId}", - //workArea.Id, workArea.FloorId, buildingId, projectId); return true; } - - //_logger.LogWarning("No update performed. Missing or invalid data for ProjectId: {ProjectId}", projectId); return false; } public async Task?> GetBuildingInfraFromCache(Guid projectId) @@ -333,15 +311,6 @@ namespace Marco.Pms.CacheHelper .Project(p => p.Buildings) .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; } public async Task UpdatePlannedAndCompleteWorksInBuildingFromCache(Guid workAreaId, double plannedWork, double completedWork) @@ -431,8 +400,9 @@ namespace Marco.Pms.CacheHelper return result; } + #endregion - // ------------------------------------------------------- WorkItem ------------------------------------------------------- + #region=================================================================== WorkItem Cache Helper =================================================================== public async Task> GetWorkItemsByWorkAreaIdsFromCache(List workAreaIds) { @@ -517,5 +487,7 @@ namespace Marco.Pms.CacheHelper var result = await _taskCollection.DeleteOneAsync(filter); return result.DeletedCount > 0; } + + #endregion } } diff --git a/Marco.Pms.CacheHelper/ReportCache.cs b/Marco.Pms.CacheHelper/ReportCache.cs index 76009a4..66611a8 100644 --- a/Marco.Pms.CacheHelper/ReportCache.cs +++ b/Marco.Pms.CacheHelper/ReportCache.cs @@ -1,4 +1,3 @@ -using Marco.Pms.DataAccess.Data; using Marco.Pms.Model.MongoDBModels; using Microsoft.Extensions.Configuration; using MongoDB.Driver; @@ -7,12 +6,10 @@ namespace Marco.Pms.CacheHelper { public class ReportCache { - private readonly ApplicationDbContext _context; private readonly IMongoCollection _projectReportCollection; - public ReportCache(ApplicationDbContext context, IConfiguration configuration) + public ReportCache(IConfiguration configuration) { var connectionString = configuration["MongoDB:ConnectionString"]; - _context = context; var mongoUrl = new MongoUrl(connectionString); var client = new MongoClient(mongoUrl); // Your MongoDB connection string var mongoDB = client.GetDatabase(mongoUrl.DatabaseName); // Your MongoDB Database name