Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Jun 22, 2017 @ 20:37
    Nicholas Westby
    0

    Reliable Use of UmbracoDatabase from Background Thread?

    I am inserting a record into the database from a background thread (to avoid slowing down a form submission): GitHub

    I am using an instance of UmbracoDatabase, which implements IDisposeOnRequestEnd. For whatever reason, this seems to work currently, at least most of the time (my theory is that the database insert is so fast it finishes before the request ends and disposes of the database).

    If the database is disposed of at the end of a request, what is the recommended way to reliably interact with the database from a background thread?

    FYI, this question was initiated based on some information Shannon wrote here (regarding how the database is disposed): https://github.com/kipusoep/UrlTracker/issues/146

    Also, while you probably don't need to know this, you can see the thread creation here: GitHub

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Jun 30, 2017 @ 04:48
    Nicholas Westby
    0

    To add some clarifications to my original question, there is some discussion on Twitter about this: https://twitter.com/MrMarsRed/status/880513267310895104

    Some important points:

    • Lightweight Needs to be lightweight solution. Can't go all willy nilly modifying config files and changing major default bits of architecture for a site.
    • Retain Abstractions Can't just bypass Umbraco's database abstractions by accessing connection string. This is for an open source tool that may be used on thousands of installs, so need to use core-supported methods (e.g., so it will work on SQL Server, SQL Server CE, and MySql).

    I imagine there is a very simple way of addressing this. I just don't know what it is yet.

  • Nicholas Westby 2054 posts 7100 karma points c-trib
    Jul 18, 2017 @ 23:02
    Nicholas Westby
    0

    Does anybody know of a safe way to interact with the Umbraco database from a background thread? I just found another use case I'll be needing shortly.

    Specifically, I plan on incrementing a page view count, which will facilitate a tool that allows blog articles to be sorted by popularity (popularity being determined by number of page views). I'd like to perform the database update on a background thread so it doesn't slow down the display of the blog article pages.

Please Sign in or register to post replies

Write your reply to:

Draft