Skip to content

Commit 2b4a340

Browse files
HubSpot (patch) cache properties per HubSpot portal (#475)
* HubSpot (patch) cache properties per HubSpot portal * Update src/appmixer/hubspot/commons.js thanks 🐇 Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 2dfe988 commit 2b4a340

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/appmixer/hubspot/commons.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ module.exports = {
4343
// Default cache TTL set to 1 minute as property definitions rarely change
4444
// Can be configured via context.config.objectPropertiesCacheTTL if needed
4545
const objectPropertiesCacheTTL = context.config.objectPropertiesCacheTTL || (60 * 1000);
46-
const cacheKeyPrefix = 'hubspot_properties_' + objectType;
46+
// Use hub_id from context to differentiate between different HubSpot portals/users.
47+
const portalId = context.auth?.profileInfo?.hub_id || 'default';
48+
const cacheKeyPrefix = 'hubspot_properties_' + objectType + '_' + portalId;
4749
let lock;
4850
try {
4951
lock = await context.lock(`hubspot_properties_${objectType}`);

test/hubspot/commons.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe('commons.js', () => {
1212

1313
// Reset the context.
1414
context = testUtils.createMockContext();
15+
context.auth = { profileInfo: { hub_id: '123456' } };
1516
context.messages = { in: { content: {} } };
1617
context.config = {
1718
objectPropertiesCacheTTL: 1
@@ -57,5 +58,9 @@ describe('commons.js', () => {
5758
assert(properties.length > 0);
5859
assert.equal(properties[0].label, 'Jirka Notes [custom]', 'Custom field should have [custom] suffix');
5960
assert.equal(properties[1].label, 'Job Title', 'Non custom field should not have [custom] suffix');
61+
62+
// Should use `hub_id` from context to differentiate between different HubSpot portals/users.
63+
const setCacheArgs = context.staticCache.set.getCall(0).args;
64+
assert.equal(setCacheArgs[0], 'hubspot_properties_contacts_123456_all', 'Cache key should contain hub_id');
6065
});
6166
});

0 commit comments

Comments
 (0)