Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HOSTSD-246 Fix Data Service #108

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import React from 'react';
import { toast } from 'react-toastify';
import { LineChart } from '../line';
import styles from './StorageTrendsChart.module.scss';
import { useServerHistoryItems } from './hooks';
import { useStorageTrendsData } from './useStorageTrendsData';
import { useServerHistoryItems, useStorageTrendsData } from './hooks';

ChartJS.register(CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip, Legend);

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './useServerHistoryItems';
export * from './useStorageTrendsData';
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { convertToStorageSize } from '@/utils';
import { ChartData } from 'chart.js';
import moment from 'moment';
import React from 'react';
import { generateStorageHistoryForDateRange } from '../utils';
import { generateStorageHistoryForDateRange } from '../../utils';

/**
* Generates line chart data based on the current filtered server history items.
Expand Down
1 change: 0 additions & 1 deletion src/data-service/DataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,6 @@ private async Task ProcessConfigurationItemsAsync(Models.DataSyncModel option)
}

// Check if file system item exists in HSB.
// TODO: This is noisy, but we don't want to keep all of them in memory.
var fileSystemItem = await this.HsbApi.GetFileSystemItemAsync(serviceNowKey, computerKey, fileSystemItemSN.Data.Name);
if (fileSystemItemSN.Data.InstallStatus != "1")
{
Expand Down
7 changes: 1 addition & 6 deletions src/libs/dal/Services/ServerItemService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,7 @@ join t in this.Context.Tenants on ut.TenantId equals t.Id
public override EntityEntry<ServerItem> Add(ServerItem entity)
{
// This key provides a way to link only the current history record.
var key = Guid.NewGuid();
entity.HistoryKey = key;

entity.HistoryKey = Guid.NewGuid();
var result = base.Add(entity);

// Add item to history.
Expand All @@ -198,16 +196,13 @@ public EntityEntry<ServerItem> Update(ServerItem entity, bool updateTotals)

if (updateTotals)
{
// TODO: File system items need to be removed otherwise this formula will be invalid over time.
// Grab all file system items for this server so that space can be calculated.
// The downside to this implementation is that the calculation will include the prior synced data until all file system items have been synced up.
var volumes = this.Context.FileSystemItems.AsNoTracking().Where(fsi => fsi.ServerItemServiceNowKey == entity.ServiceNowKey).ToArray();
entity.Capacity = volumes.Sum(v => v.SizeBytes);
entity.AvailableSpace = volumes.Sum(v => v.FreeSpaceBytes);
this.Context.Entry(entity).State = EntityState.Modified;

// Update current historical record too.
// TODO: File system items need to be removed otherwise this formula will be invalid over time.
var history = this.Context.ServerHistoryItems.FirstOrDefault(shi => shi.ServiceNowKey == entity.ServiceNowKey && shi.HistoryKey == entity.HistoryKey);
if (history != null)
{
Expand Down
3 changes: 3 additions & 0 deletions src/libs/models/ServerItemModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class ServerItemModel : AuditableModel
{
#region Properties
public string ServiceNowKey { get; set; } = "";
public Guid? HistoryKey { get; set; }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was causing the bug


public int? TenantId { get; set; }
public TenantModel? Tenant { get; set; }
Expand Down Expand Up @@ -48,6 +49,7 @@ public ServerItemModel() { }
public ServerItemModel(ServerItem entity) : base(entity)
{
this.ServiceNowKey = entity.ServiceNowKey;
this.HistoryKey = entity.HistoryKey;

this.TenantId = entity.TenantId;
this.OrganizationId = entity.OrganizationId;
Expand Down Expand Up @@ -118,6 +120,7 @@ public static explicit operator ServerItem(ServerItemModel model)
return new ServerItem(model.TenantId, model.OrganizationId, model.OperatingSystemItemId, model.RawData, model.RawDataCI)
{
ServiceNowKey = model.ServiceNowKey,
HistoryKey = model.HistoryKey,
ClassName = model.ClassName,
Name = model.Name,
InstallStatus = model.InstallStatus,
Expand Down
Loading