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

Added expiration of documents #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

hiddenshadow21
Copy link

No description provided.

if (ExpirationOffsetInDays > 0)
{
var expiry = DateTime.UtcNow.AddDays(ExpirationOffsetInDays);
bulkInsert.Store(logEntry, new MetadataAsDictionary
Copy link
Contributor

@snakefoot snakefoot Sep 26, 2022

Choose a reason for hiding this comment

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

Could one make a single MetadataAsDictionary-instance (outside the loop), and use the same instance for all logEntries?

Copy link
Author

Choose a reason for hiding this comment

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

Now using one instance for all entries.

var expiry = DateTime.UtcNow.AddDays(ExpirationOffsetInDays);
bulkInsert.Store(logEntry, new MetadataAsDictionary
{
new KeyValuePair<string, object>("@expires", expiry)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use Constants.Documents.Metadata.Expires instead of "@expires" ?

Copy link
Author

Choose a reason for hiding this comment

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

Changed to available constant.

/// <summary>
/// Expiration date of document
/// </summary>
public int ExpirationOffsetInDays { get; set; }
Copy link
Contributor

@snakefoot snakefoot Sep 26, 2022

Choose a reason for hiding this comment

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

Maybe rename to ExpiryDays ? (Easier to spell) Or TimeToLiveDays ?

Copy link
Author

Choose a reason for hiding this comment

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

Renamed.

@@ -9,7 +9,7 @@
</extensions>
<targets>
<target name="raven" xsi:type="BufferingWrapper" flushTimeout="7000">
<target xsi:type="Raven" IdType="Guid" CollectionName="LogEntries" Urls="http://ws-1:8080;Database=RavenNLog">
<target xsi:type="Raven" IdType="Guid" CollectionName="LogEntriesExpire" Urls="http://localhost:8080" Database="logs" ExpirationOffsetInDays="3">
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename from ExpirationOffsetInDays to new ExpiryDays

@@ -122,11 +128,24 @@ protected override void Write(IList<AsyncLogEventInfo> logEvents)
{
using (var bulkInsert = _documentStore.BulkInsert())
{
for (int i = 0; i < logEvents.Count; ++i)
var expiry = DateTime.UtcNow.AddDays(ExpiryDays);
Copy link
Contributor

@snakefoot snakefoot Jan 23, 2023

Choose a reason for hiding this comment

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

Consider doing this:

var expiryMetaData = ExpiryDays > 0 ? new MetadataAsDictionary
{
     new KeyValuePair<string, object>(Constants.Documents.Metadata.Expires, DateTime.UtcNow.AddDays(ExpiryDays))
} : null;

var logEntry = CreateLogEntry(logEvent);
bulkInsert.Store(logEntry);
if (ExpiryDays > 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

Then use it like this:

if (expiryMetaData != null
{
    bulkInsert.Store(logEntry, expirationMetadata);
}
else
{
    bulkInsert.Store(logEntry);
}

Copy link
Contributor

@snakefoot snakefoot left a comment

Choose a reason for hiding this comment

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

I think it looks good. @kentcooper Ready for merge?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants