简单地说,我在 Child 类和 Parent 类上有一个多对一的关系。我想加载所有孩子而不必加载他们的父母详细信息。我的孩子班级是
@Entity
public class Child implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parentId", referencedColumnName = "id")
private Parent parent;
public Child() {
}
// Getters and setters here
}
Run Code Online (Sandbox Code Playgroud)
我的父类是
@Entity
public class Parent implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
public Parent() {
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个休息控制器,我想用它来获取所有没有父母的孩子
@GetMapping
public List<Child> getChildren() {
return childRepository.findAll();
}
Run Code Online (Sandbox Code Playgroud)
当我运行它时它会抛出
{
"timestamp": "2019-02-22T13:45:31.219+0000", …Run Code Online (Sandbox Code Playgroud) 我创建了共享模块,我在其中导入了 angular ag - grid。所以,按照股份公司-网的办公场所,我们必须写AgGridModule.withComponents([]) 在imports。
但是我也必须导出它,因为我想将此导出用作我的延迟加载模块之一中的导入,而不是直接在appModule.
但是AgGridModule.withComponents([])从共享模块导出给了我错误。
共享模块.ts
import { AgGridModule } from 'ag-grid-angular';
imports: [
AgGridModule.withComponents([])
]
enter code here`enter code here`
exports: [
AgGridModule.withComponents([]) // this export is giving error
]
Run Code Online (Sandbox Code Playgroud)
错误描述:
Run Code Online (Sandbox Code Playgroud)Type 'ModuleWithProviders<any>' is not assignable to type 'any[] | Type<any>'. Type 'ModuleWithProviders<any>' is missing the following properties from type 'Type<any>': apply, call, bind, prototype, and 5 more
我在 Next js 站点的索引页上放置了一个 Google Maps API 组件,但它使加载速度大幅减慢(大约 500 毫秒)。
有没有办法让我使用 useEffect 挂钩或其他简洁的方式将组件延迟到页面加载之后?
我想提高网站的加载速度(和性能得分)。
export default function Home() {
return (
<div className={styles.main}>
<Layout>
<main className={styles.content}>
**<div className={styles.mapContainer}>
<Map className={styles.map}/>**
</div>
</main>
</Layout>
</div>
)
}
Run Code Online (Sandbox Code Playgroud) 请参阅下面的示例,
function doSomething1(){/*needs ss*/const ss = SpreadsheetApp.openById(/*SPREADSHEET_ID*/);}
function doSomething2(){/*needs ss*/const ss = SpreadsheetApp.openById(/*SPREADSHEET_ID*/);}
function doItAll(){
doSomething1();
doSomething2();
}
Run Code Online (Sandbox Code Playgroud)
可以使用全局变量来简化,而不是在两个函数中调用 Spreadsheet
const ss = SpreadsheetApp.openById(/*SPREADSHEET_ID*/);
function doSomething1(){/*do something with ss*/}
function doSomething2(){/*do something with ss*/}
function doItAll(){
doSomething1();
doSomething2();
}
Run Code Online (Sandbox Code Playgroud)
这里的问题可以在不使用全局变量的情况下通过简单地ss在函数之间传递变量来解决。但是,由于多个函数需要访问该变量,这会变得更加复杂ss。而且通过ss很麻烦。没有太多方法可以避免应用程序脚本中的全局。不支持模块。如果您使用 IIFE,则所有函数都对 IDE 隐藏,从而无法从 IDE 或其他任何地方调用函数。在这里使用全局要优雅得多。但如果我有一个简单的触发器,就会出现问题:
const ss = SpreadsheetApp.openById(/*SPREADSHEET_ID*/);
function doSomething1(){/*do something with ss*/}
function doSomething2(){/*do something with ss*/}
function doItAll(){
doSomething1();
doSomething2();
}
function onOpen(){/*Adds a menu*/}
Run Code Online (Sandbox Code Playgroud)
添加菜单将失败,因为此行之前onOpen已加载,并且此行需要权限/授权,而作为简单触发器,不会使用任何需要授权的代码运行。SpreadsheetApp.openById(/*SPREADSHEET_ID*/)onOpenonOpen …
lazy-loading global-variables google-sheets google-apps-script
我正在用Serenity用 Rust 编写一个不和谐的机器人。为了填充一些嵌入标头,我需要与机器人相关的信息(用户和所有者,以下称为BOT),并且我尝试使用Once_cellLazy板条箱中的结构来实现这一点。
问题是这些BOT数据只能使用 Serenity 的 Http 模块的异步函数来查询,而我正在努力使其工作。
我设置了一些斜杠命令,每个命令都有自己的处理函数。当我BOT从这些处理程序函数之一取消引用(这就是应该评估它(仅一次),对吧?)时,我的Lazy闭包在它遇到的第一个函数上阻塞.await。
另一方面,当我BOT从main(tokio async)取消引用时,它才起作用。
因此,以下代码在从特定斜杠命令处理程序 (BoxedFuture) 取消引用时打印“0,1,2,3” BOT,main但仅打印“0,1”:
use once_cell::sync::Lazy;
use serenity::{http::Http, model::user::User};
pub struct Bot {
pub user: User,
pub owner: User,
}
pub static BOT: Lazy<Bot> = Lazy::new(|| {
println!("0");
let http_client = Http::new(env!("DISCORD_BOT_TOKEN"));
futures::executor::block_on(async {
println!("1");
let user = http_client
.get_current_user()
.await
.expect("An HTTP client error occured")
.into();
println!("2"); …Run Code Online (Sandbox Code Playgroud) 我正在为非常有限的硬件开发一个应用程序,并决定使用 jetpack compose。
当我需要显示卡片列表并且用于它的惰性行变得非常滞后时,问题就出现了。为了进行比较,我选择了一个带有 recyclerView 的示例项目,并用它来显示大致相同的卡片列表,并且滚动尽可能平滑。jetpack compose 本质上比 xml view 慢还是我做错了什么?
撰写代码(我无法准确分享我的代码,但可组合的卡片只是一张带有一些图像、图标和文本的卡片):
@Composable
fun mainComposable(){
...
cardList = remember{ arrayListOf(...) }
lazyList(cardList)
...
}
@Composable
fun lazyList(
cardList: List<CardContent>,
){
LazyRow(
horizontalArrangement = Arrangement.spacedBy(16.dp),
contentPadding = PaddingValues(horizontal = 32.dp)
) {
items(
items = cardList,
key = { it.id }) { item ->
CardComposable(
content = item
)
}
}
}
Run Code Online (Sandbox Code Playgroud)
我已经花了一些时间搜索,所以我发现了很多优化,比如在发布模式下运行,在 build.gradle 上将 minifyEnabled 和收缩资源设置为 true,在 gradle.properties 中将 android.enableR8.fullMode 设置为 true,使用 LazyRow 上的键他们有所帮助,但滚动仍然比带有 recyclerView 的等效 xml 视图应用程序慢。
编辑:添加了 CardComposable …
optimization android lazy-loading android-xml android-jetpack-compose
我正在学习 Angular 培训课程(使用 Angular 12)。
{ path: 'training', loadChildren: './training/training.module.ts#TrainingModule'},
Run Code Online (Sandbox Code Playgroud)
不管用:
未处理的 Promise 拒绝:找不到模块 './training/training.module.ts' ;区域: ; 任务:Promise.then;值:错误:找不到模块'./training/training.module.ts
我 100% 确定路径来自app-routing.module.ts是正确的(我复制/粘贴了它,以确保)。
然而,之前的课程(由同一位演讲者)让我认为正确的语法应该是:
{path: 'training', loadChildren: () => import('./training/training.module').then(module => module.TrainingModule)}
Run Code Online (Sandbox Code Playgroud)
为什么有这两种可能性?它们在功能上等效吗?我什么时候应该使用哪个?
在Angular 6中,我创建了惰性模块,在路由时加载需要花费很多时间.
有没有办法在角度6中创建更快的Web应用程序?
我正在使用的插件:http: //www.appelsiini.net/projects/lazyload
我想对动态加载的内容使用延迟加载.即使用加载的内容
$.ajax({
type: "POST",
url: "some.php",
data: postdata,
success:function(data) {
$('#somediv').html(data);
//Do lazy loading now.
}
})
Run Code Online (Sandbox Code Playgroud)
懒惰负载启动
$("img.lazy").show().lazyload();
Run Code Online (Sandbox Code Playgroud) lazy-loading ×9
angular ×3
javascript ×2
android ×1
android-xml ×1
asynchronous ×1
discord ×1
hibernate ×1
java ×1
jquery ×1
many-to-one ×1
module ×1
next.js ×1
optimization ×1
performance ×1
persistence ×1
reactjs ×1
rust ×1