All Projects → dlukez → dataloader-dotnet

dlukez / dataloader-dotnet

Licence: MIT license
DataLoader for .NET

Programming Languages

C#
18002 projects
powershell
5483 projects

Projects that are alternatives of or similar to dataloader-dotnet

Java Dataloader
A Java 8 port of Facebook DataLoader
Stars: ✭ 367 (+817.5%)
Mutual labels:  batch, dataloader
Dataloader
DataLoader is a generic utility to be used as part of your application's data fetching layer to provide a consistent API over various backends and reduce requests to those backends via batching and caching.
Stars: ✭ 11,040 (+27500%)
Mutual labels:  batch, dataloader
Dataloader Php
DataLoaderPhp is a generic utility to be used as part of your application's data fetching layer to provide a simplified and consistent API over various remote data sources such as databases or web services via batching and caching.
Stars: ✭ 160 (+300%)
Mutual labels:  batch, dataloader
mongoose-plugin-cache
The Perfect Marriage of MongoDB and Redis
Stars: ✭ 42 (+5%)
Mutual labels:  batch
aly
Command Line Alias Manager and Plugin System - Written in Golang
Stars: ✭ 21 (-47.5%)
Mutual labels:  batch
RCWM
Right Click Windows Magic is an open-source set of right-click (context) menu tools for admins, power users and other magic beings. Batch&Powershell.
Stars: ✭ 39 (-2.5%)
Mutual labels:  batch
KGrabber
Userscript for extracting links from kissanime.ru and similar sites.
Stars: ✭ 29 (-27.5%)
Mutual labels:  batch
ocr2text
Convert a PDF via OCR to a TXT file in UTF-8 encoding
Stars: ✭ 90 (+125%)
Mutual labels:  batch
BatchPayments
A gas conscious batch payment implementation
Stars: ✭ 27 (-32.5%)
Mutual labels:  batch
quarkus-jberet
Quarkus Extension for Batch Applications.
Stars: ✭ 26 (-35%)
Mutual labels:  batch
Batch-Antivirus
Batch Antivirus, a powerful antivirus suite written in batch with real-time protection and heuristical scanning.
Stars: ✭ 26 (-35%)
Mutual labels:  batch
terraform-scheduled-batch-job
A Terraform module representing a scheduled Batch job
Stars: ✭ 22 (-45%)
Mutual labels:  batch
SFDX-Data-Move-Utility-Desktop-App
This repository contains the special Desktop GUI Application, that will help you to prepare and execute data migration packages using the SFDMU Plugin.
Stars: ✭ 65 (+62.5%)
Mutual labels:  dataloader
Windows-10-tweaks
This repo contains multiple scripts to optimize windows 10
Stars: ✭ 37 (-7.5%)
Mutual labels:  batch
Batch-First
A JIT compiled chess engine which traverses the search tree in batches in a best-first manner, allowing for neural network batching, asynchronous GPU use, and vectorized CPU computations.
Stars: ✭ 27 (-32.5%)
Mutual labels:  batch
MobilePose
Light-weight Single Person Pose Estimator
Stars: ✭ 588 (+1370%)
Mutual labels:  dataloader
GraphOne
"GraphOne: A Data Store for Real-time Analytics on Evolving Graphs", Usenix FAST'19
Stars: ✭ 46 (+15%)
Mutual labels:  batch
ee.Screen
Takes screenshots of web pages for the list of URLs. Various resolutions, multiple formats (JPG, PDF, PNG and TXT)
Stars: ✭ 19 (-52.5%)
Mutual labels:  batch
sync-engine-example
Synchronization Algorithm Exploration: Techniques to synchronize a SQL database with external destinations.
Stars: ✭ 17 (-57.5%)
Mutual labels:  batch
batchql
GraphQL security auditing script with a focus on performing batch GraphQL queries and mutations
Stars: ✭ 251 (+527.5%)
Mutual labels:  batch

DataLoader for .NET

A port of Facebook's DataLoader for .NET.

NuGet MyGet Pre Release MyGet Build Status

This project began as a solution to the select N+1 problem for GraphQL .NET but was implemented as a standalone package that is completely decoupled from any framework.

It leverages .NET's async/await feature to enable query batching (a la Facebook's Dataloader) that should work out of the box, without requiring significant changes to an existing codebase.

If anyone finds this useful outside of GraphQL, feel free to drop me a message - I'm interested to know of other potential applications that could be catered to.

Check out the sample to see it used in a GraphQL implementation.

Caveats

Facebook's implementation runs in Javascript and takes advantage of the event loop to fire any pending requests for ID's collected during the previous frame. Unfortunately, not all .NET applications run in an event loop.

As such, we have defined a special frame or context to contain our load operations. Whenever we want to use a loader, we should be inside one of these contexts. A simple way to do this is by calling the static DataLoaderContext.Run method. This method takes a user-supplied delegate and runs it in within a new context, before actually executing any loaders that were called within it.

Usage

There are two ways loaders can be used.

Method 1: Bound/explicit context (recommended)

With this approach, loader instances are obtained for a particular context using the context's GetDataLoader methods. Along with the user-supplied fetch callback, these methods also take a key for caching and reusing instances.

var results = await DataLoaderContext.Run(async loadCtx =>
{
    // Here we obtain a loader using the context's factory method.
    var droidLoader = loadCtx.Factory.GetDataLoader<int, Droid>("droids", ids =>
    {
        using (var db = new StarWarsContext())
        {
            return db.Droid.Where(d => ids.Contains(d.Id)).ToListAsync();
        }
    });

    // Queue up some loads.
    var task1 = droidLoader.LoadAsync(1);
    var task2 = droidLoader.LoadAsync(2);
    var task3 = droidLoader.LoadAsync(3);

    // Await the results... Control is yielded to the framework and the loader is fired.
    var results = Task.WhenAll(task1, task2, task3);

    // We have the results, but let's load some more! Run ensures that asynchronous
    // continuations behave like the initial call - ID's should be collected and
    // fetched as a batch after continuations have run.
    var task4 = droidLoader.LoadAsync(4);
    var task5 = droidLoader.LoadAsync(5);

    // Return all our results.
    return (await Task.WhenAll(task4, task5)).Concat(results);
));

Example 2: Unbound/implicit context

// Create a floating/unbound loader that will attach itself to the context
// that's currently active at the time a load method is called.
var personLoader = new DataLoader<int, Person>(ids =>
{
    using (var db = new StarWarsContext())
    {
        return db.Person.Where(p => ids.Contains(p.Id)).ToListAsync();
    }
});

var results = await DataLoaderContext.Run(async () =>
{
    // We have an implicit context here.
    Debug.Assert(DataLoaderContext.Current != null);

    // Queue up some person loads.
    var task1 = personLoader.LoadAsync(1);
    var task2 = personLoader.LoadAsync(2);
    var task3 = personLoader.LoadAsync(3);

    // Await the results... Control is yielded to the framework and the loader is fired.
    var results = await Task.WhenAll(task1, task2, task3);

    // We have the results, but let's load some more! Run ensures that asynchronous
    // continuations behave like the initial call - ID's should be collected and
    // fetched as a batch after continuations have run.
    var task4 = personLoader.LoadAsync(4);
    var task5 = personLoader.LoadAsync(5);

    // Return all our results.
    return (await Task.WhenAll(task4, task5)).Concat(results);
});

To Do

  • Basic support
  • Support async fetching
  • Cancellation
  • Benchmarks
  • Multithreaded performance

Ideas

  • Single worker thread to service loaders
  • Sync context to handle async/await in load continuations
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].