@memberjunction/core
Advanced tools
Comparing version 2.1.5 to 2.2.0
@@ -241,2 +241,9 @@ import { BaseEntity } from "./baseEntity"; | ||
/** | ||
* Returns the timestamp of the local cached version of a given datasetName or null if there is no local cache for the | ||
* specified dataset | ||
* @param datasetName the name of the dataset to check | ||
* @param itemFilters optional filters to apply to the dataset | ||
*/ | ||
GetLocalDatasetTimestamp(datasetName: string, itemFilters?: DatasetItemFilterType[]): Promise<Date>; | ||
/** | ||
* This routine checks to see if the local cache version of a given datasetName/itemFilters combination is up to date with the server or not | ||
@@ -243,0 +250,0 @@ * @param datasetName |
@@ -151,2 +151,9 @@ import { BaseEntity } from "./baseEntity"; | ||
/** | ||
* Returns the timestamp of the local cached version of a given datasetName or null if there is no local cache for the | ||
* specified dataset | ||
* @param datasetName the name of the dataset to check | ||
* @param itemFilters optional filters to apply to the dataset | ||
*/ | ||
GetLocalDatasetTimestamp(datasetName: string, itemFilters?: DatasetItemFilterType[]): Promise<Date>; | ||
/** | ||
* This routine checks to see if the local cache version of a given datasetName/itemFilters combination is up to date with the server or not | ||
@@ -153,0 +160,0 @@ * @param datasetName |
@@ -351,8 +351,8 @@ "use strict"; | ||
/** | ||
* This routine checks to see if the local cache version of a given datasetName/itemFilters combination is up to date with the server or not | ||
* @param datasetName | ||
* @param itemFilters | ||
* @returns | ||
* Returns the timestamp of the local cached version of a given datasetName or null if there is no local cache for the | ||
* specified dataset | ||
* @param datasetName the name of the dataset to check | ||
* @param itemFilters optional filters to apply to the dataset | ||
*/ | ||
async IsDatasetCacheUpToDate(datasetName, itemFilters) { | ||
async GetLocalDatasetTimestamp(datasetName, itemFilters) { | ||
const ls = this.LocalStorageProvider; | ||
@@ -364,30 +364,38 @@ if (ls) { | ||
if (val) { | ||
// we have a local cached timestamp, so compare it to the server timestamp | ||
const status = await this.GetDatasetStatusByName(datasetName, itemFilters); | ||
if (status) { | ||
const serverTimestamp = status.LatestUpdateDate.getTime(); | ||
const localTimestamp = new Date(val); | ||
if (localTimestamp.getTime() >= serverTimestamp) { | ||
// this situation means our local cache timestamp is >= the server timestamp, so we're most likely up to date | ||
// in this situation, the last thing we check is for each entity, if the rowcount is the same as the server, if it is, we're good | ||
// iterate through all of the entities and check the row counts | ||
const localDataset = await this.GetCachedDataset(datasetName, itemFilters); | ||
for (const eu of status.EntityUpdateDates) { | ||
const localEntity = localDataset.Results.find(e => e.EntityID === eu.EntityID); | ||
if (!localEntity || localEntity.Results.length !== eu.RowCount) { | ||
// we either couldn't find the entity in the local cache or the row count is different, so we're out of date | ||
// the RowCount being different picks up on DELETED rows. The UpdatedAt check which is handled above would pick up | ||
// on any new rows or updated rows. This approach makes sure we detect deleted rows and refresh the cache. | ||
return false; | ||
} | ||
return new Date(val); | ||
} | ||
} | ||
} | ||
/** | ||
* This routine checks to see if the local cache version of a given datasetName/itemFilters combination is up to date with the server or not | ||
* @param datasetName | ||
* @param itemFilters | ||
* @returns | ||
*/ | ||
async IsDatasetCacheUpToDate(datasetName, itemFilters) { | ||
const localDate = await this.GetLocalDatasetTimestamp(datasetName, itemFilters); | ||
if (localDate) { | ||
// we have a local cached timestamp, so compare it to the server timestamp | ||
const status = await this.GetDatasetStatusByName(datasetName, itemFilters); | ||
if (status) { | ||
const serverTimestamp = status.LatestUpdateDate.getTime(); | ||
if (localDate.getTime() >= serverTimestamp) { | ||
// this situation means our local cache timestamp is >= the server timestamp, so we're most likely up to date | ||
// in this situation, the last thing we check is for each entity, if the rowcount is the same as the server, if it is, we're good | ||
// iterate through all of the entities and check the row counts | ||
const localDataset = await this.GetCachedDataset(datasetName, itemFilters); | ||
for (const eu of status.EntityUpdateDates) { | ||
const localEntity = localDataset.Results.find(e => e.EntityID === eu.EntityID); | ||
if (!localEntity || localEntity.Results.length !== eu.RowCount) { | ||
// we either couldn't find the entity in the local cache or the row count is different, so we're out of date | ||
// the RowCount being different picks up on DELETED rows. The UpdatedAt check which is handled above would pick up | ||
// on any new rows or updated rows. This approach makes sure we detect deleted rows and refresh the cache. | ||
return false; | ||
} | ||
// if we get here that means that the row counts are the same for all entities and we're up to date | ||
return true; | ||
} | ||
else { | ||
// our local cache timestamp is < the server timestamp, so we're out of date | ||
return false; | ||
} | ||
// if we get here that means that the row counts are the same for all entities and we're up to date | ||
return true; | ||
} | ||
else { | ||
// our local cache timestamp is < the server timestamp, so we're out of date | ||
return false; | ||
@@ -397,5 +405,10 @@ } | ||
else { | ||
// we couldn't get the server status, so we're out of date | ||
return false; | ||
} | ||
} | ||
else { | ||
// we don't have a local cache timestamp, so we're out of date | ||
return false; | ||
} | ||
} | ||
@@ -402,0 +415,0 @@ /** |
{ | ||
"name": "@memberjunction/core", | ||
"version": "2.1.5", | ||
"version": "2.2.0", | ||
"description": "MemberJunction: Core Library including Metadata, Application, Entity Retrieval and Manipulation, and Utilities", | ||
@@ -22,3 +22,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"@memberjunction/global": "2.1.5", | ||
"@memberjunction/global": "2.2.0", | ||
"rxjs": "^7.8.1", | ||
@@ -25,0 +25,0 @@ "zod": "^3.23.8" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
586859
8468
+ Added@memberjunction/global@2.2.0(transitive)
- Removed@memberjunction/global@2.1.5(transitive)
Updated@memberjunction/global@2.2.0