Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

fix(buffer): fixed issues with buffer

Carl-Gerhard Lindesvärde18ac4d79eb7
diff --git a/packages/db/src/buffers/buffer.ts b/packages/db/src/buffers/buffer.ts
index de3299bef..2035223c9 100644
--- a/packages/db/src/buffers/buffer.ts
+++ b/packages/db/src/buffers/buffer.ts
@@ -103,6 +103,7 @@ export class RedisBuffer<T> {
await cb();
} catch (e) {
this.logger.error(`#2 Failed to execute callback: ${cb.name}`, e);
+ throw e;
}
}
}
@@ -160,14 +161,14 @@ export class RedisBuffer<T> {
},
);
} catch (error) {
- this.logger.error('Failed to process queue while flushing buffer}:', {
+ this.logger.error('Failed to process queue while flushing buffer', {
error,
queueSize: items.length,
});
if (items.length > 0) {
// Add back items to keep
- this.logger.debug('Adding all items back to buffer');
+ this.logger.info('Adding all items back to buffer');
await getRedisCache().lpush(
this.getKey(),
...items.map((item) => JSON.stringify(item)),
diff --git a/packages/db/src/buffers/event-buffer.ts b/packages/db/src/buffers/event-buffer.ts
index 1253d5d8a..3920c5898 100644
--- a/packages/db/src/buffers/event-buffer.ts
+++ b/packages/db/src/buffers/event-buffer.ts
@@ -67,7 +67,8 @@ export class EventBuffer extends RedisBuffer<BufferType> {
return (
lastEvent.project_id === item.project_id &&
lastEvent.profile_id === item.profile_id &&
- lastEvent.path !== ''
+ lastEvent.path !== '' &&
+ lastEvent.name === 'screen_view'
);
});
@@ -76,6 +77,10 @@ export class EventBuffer extends RedisBuffer<BufferType> {
item,
);
+ if (!event.properties) {
+ event.properties = {};
+ }
+
if (lastEventWithData) {
event.properties.__properties_from = lastEventWithData.id;
}
@@ -114,9 +119,12 @@ export class EventBuffer extends RedisBuffer<BufferType> {
new Date(item.created_at).getTime();
const event = {
...item,
+ properties: {
+ ...(item?.properties || {}),
+ __duration_from: nextScreenView.id,
+ },
duration,
};
- event.properties.__duration_from = nextScreenView.id;
toInsert.add(event);
} else if (hasSessionEnd) {
// push last event in session if we have a session_end event